Ejemplo n.º 1
0
    def __init__(self, stdscr, lineObjs):
        curses.use_default_colors()
        self.stdscr = stdscr
        self.colorPrinter = ColorPrinter(self.stdscr)

        self.lineObjs = lineObjs
        self.hoverIndex = 0
        self.scrollOffset = 0
        self.scrollBar = ScrollBar(self.colorPrinter, lineObjs, self)
        self.helperChrome = HelperChrome(self.colorPrinter, self)
        (self.oldmaxy, self.oldmaxx) = self.getScreenDimensions()
        self.mode = SELECT_MODE

        self.simpleLines = []
        self.lineMatches = []
        # lets loop through and split
        for key, lineObj in self.lineObjs.items():
            lineObj.setController(self)
            if (lineObj.isSimple()):
                self.simpleLines.append(lineObj)
            else:
                self.lineMatches.append(lineObj)

        self.numLines = len(lineObjs.keys())
        self.numMatches = len(self.lineMatches)

        self.setHover(self.hoverIndex, True)

        # the scroll offset might not start off
        # at 0 if our first real match is WAY
        # down the screen -- so lets init it to
        # a valid value after we have all our line objects
        self.updateScrollOffset()
        logger.addEvent('init')
Ejemplo n.º 2
0
def getEditorAndPath():
    editor_path = os.environ.get("FPP_EDITOR") or os.environ.get("VISUAL") or os.environ.get("EDITOR")
    if editor_path:
        editor = os.path.basename(editor_path)
        logger.addEvent("using_editor_" + editor)
        return editor, editor_path
    return "vim", "vim"
Ejemplo n.º 3
0
    def beginEnterCommand(self):
        self.stdscr.erase()
        # first check if they are trying to enter command mode
        # but already have a command...
        if len(self.flags.getPresetCommand()):
            self.helperChrome.output(self.mode)
            (_, minY, _, maxY) = self.getChromeBoundaries()
            yStart = (maxY + minY) / 2 - 3
            self.printProvidedCommandWarning(yStart)
            self.stdscr.refresh()
            self.getKey()
            self.mode = SELECT_MODE
            self.dirtyAll()
            return

        self.mode = COMMAND_MODE
        self.helperChrome.output(self.mode)
        logger.addEvent('enter_command_mode')

        command = self.showAndGetCommand()
        if len(command) == 0:
            # go back to selection mode and repaint
            self.mode = SELECT_MODE
            self.cursesAPI.noecho()
            self.dirtyAll()
            logger.addEvent('exit_command_mode')
            return
        lineObjs = self.getFilesToUse()
        output.execComposedCommand(command, lineObjs)
        sys.exit(0)
Ejemplo n.º 4
0
    def __init__(self, stdscr, lineObjs):
        self.stdscr = stdscr
        self.lineObjs = lineObjs
        self.hoverIndex = 0
        self.scrollOffset = 0
        self.scrollBar = ScrollBar(stdscr, lineObjs, self)
        self.helperChrome = HelperChrome(stdscr, self)
        (self.oldmaxy, self.oldmaxx) = self.getScreenDimensions()
        self.mode = SELECT_MODE

        self.simpleLines = []
        self.lineMatches = []
        # lets loop through and split
        for key, lineObj in self.lineObjs.items():
            lineObj.setController(self)
            if (lineObj.isSimple()):
                self.simpleLines.append(lineObj)
            else:
                self.lineMatches.append(lineObj)

        self.numLines = len(lineObjs.keys())
        self.numMatches = len(self.lineMatches)

        self.setHover(self.hoverIndex, True)
        curses.use_default_colors()
        logger.addEvent('init')
Ejemplo n.º 5
0
def getEditorAndPath():
    editor_path = os.environ.get('FPP_EDITOR') or os.environ.get('EDITOR')
    if editor_path:
        editor = os.path.basename(editor_path)
        logger.addEvent('using_editor_' + editor)
        return editor, editor_path
    return 'vim', 'vim'
Ejemplo n.º 6
0
def editFiles(lineObjs):
    partialCommands = []
    logger.addEvent('editing_num_files', len(lineObjs))
    for lineObj in lineObjs:
        (file, num) = (lineObj.getFile(), lineObj.getLineNum())
        partialCommands.append(getEditFileCommand(file, num))
    command = joinEditCommands(partialCommands)
    appendToFile(command)
Ejemplo n.º 7
0
def execComposedCommand(command, lineObjs):
    if not len(command):
        editFiles(lineObjs)
        return
    logger.addEvent('command_on_num_files', len(lineObjs))
    command = composeCommand(command, lineObjs)
    command = expandAliases(command)
    writeFriendlyCommand(command)
Ejemplo n.º 8
0
def editFiles(lineObjs):
    logger.addEvent('editing_num_files', len(lineObjs))
    filesAndLineNumbers = [(lineObj.getPath(), lineObj.getLineNum())
                           for lineObj in lineObjs]
    command = joinFilesIntoCommand(filesAndLineNumbers)
    appendIfInvalid(lineObjs)
    appendToFile(command)
    appendExit()
Ejemplo n.º 9
0
 def __init__(self, printer, screenControl):
     self.printer = printer
     self.screenControl = screenControl
     self.WIDTH = 50
     if self.getIsSidebarMode():
         logger.addEvent('init_wide_mode')
     else:
         logger.addEvent('init_narrow_mode')
Ejemplo n.º 10
0
 def onEnter(self):
     lineObjs = self.getFilesToUse()
     if not lineObjs:
         # nothing selected, assume we want hovered
         lineObjs = self.getHoveredFiles()
     logger.addEvent('selected_num_files', len(lineObjs))
     output.editFiles(lineObjs)
     sys.exit(0)
Ejemplo n.º 11
0
def execComposedCommand(command, lineObjs):
    if not len(command):
        editFiles(lineObjs)
        return
    logger.addEvent('command_on_num_files', len(lineObjs))
    command = composeCommand(command, lineObjs)
    appendAliasExpansion()
    appendIfInvalid(lineObjs)
    appendFriendlyCommand(command)
Ejemplo n.º 12
0
 def checkResize(self):
     (maxy, maxx) = self.getScreenDimensions()
     if (maxy is not self.oldmaxy or maxx is not self.oldmaxx):
         # we resized so print all!
         self.printAll()
         self.resetDirty()
         self.stdscr.refresh()
         logger.addEvent('resize')
     (self.oldmaxy, self.oldmaxx) = self.getScreenDimensions()
Ejemplo n.º 13
0
    def __init__(self, stdscr, screenControl):
        self.stdscr = stdscr
        self.screenControl = screenControl
        self.mode = None

        if self.is_sidebar_mode:
            logger.addEvent('init_wide_mode')
        else:
            logger.addEvent('init_narrow_mode')
Ejemplo n.º 14
0
def editFiles(lineObjs):
    partialCommands = []
    logger.addEvent('editing_num_files', len(lineObjs))
    for lineObj in lineObjs:
        file, num = lineObj.file, lineObj.number
        partialCommands.append(getEditFileCommand(file, num))
    command = joinEditCommands(partialCommands)
    appendIfInvalid(lineObjs)
    appendToFile(command)
Ejemplo n.º 15
0
 def __init__(self, printer, screenControl, flags):
     self.printer = printer
     self.screenControl = screenControl
     self.flags = flags
     self.WIDTH = 50
     self.SIDEBAR_Y = 0
     self.DESCRIPTION_CLEAR = True
     if self.getIsSidebarMode():
         logger.addEvent('init_wide_mode')
     else:
         logger.addEvent('init_narrow_mode')
Ejemplo n.º 16
0
 def __init__(self, printer, screenControl, flags):
     self.printer = printer
     self.screenControl = screenControl
     self.flags = flags
     self.WIDTH = 50
     self.SIDEBAR_Y = 0
     self.DESCRIPTION_CLEAR = True
     if self.getIsSidebarMode():
         logger.addEvent('init_wide_mode')
     else:
         logger.addEvent('init_narrow_mode')
Ejemplo n.º 17
0
def execComposedCommand(command, lineObjs):
    if not len(command):
        editFiles(lineObjs)
        return

    if not isinstance(command, str):
        command = command.decode()

    logger.addEvent('command_on_num_files', len(lineObjs))
    command = composeCommand(command, lineObjs)
    appendAliasExpansion()
    appendIfInvalid(lineObjs)
    appendFriendlyCommand(command)
    appendExit()
Ejemplo n.º 18
0
    def onEnter(self):
        lineObjs = self.getFilesToUse()
        if not lineObjs:
            # nothing selected, assume we want hovered
            lineObjs = self.getHoveredFiles()
        logger.addEvent('selected_num_files', len(lineObjs))

        # commands passed from the command line get used immediately
        presetCommand = self.flags.getPresetCommand()
        if len(presetCommand) > 0:
            output.execComposedCommand(presetCommand, lineObjs)
        else:
            output.editFiles(lineObjs)

        sys.exit(0)
Ejemplo n.º 19
0
    def onEnter(self):
        lineObjs = self.getPathsToUse()
        if not lineObjs:
            # nothing selected, assume we want hovered
            lineObjs = self.getHoveredPaths()
        logger.addEvent('selected_num_files', len(lineObjs))

        # commands passed from the command line get used immediately
        presetCommand = self.flags.getPresetCommand()
        if len(presetCommand) > 0:
            output.execComposedCommand(presetCommand, lineObjs)
        else:
            output.editFiles(lineObjs)

        sys.exit(0)
Ejemplo n.º 20
0
    def __init__(self, printer, lines, screenControl):
        self.printer = printer
        self.screenControl = screenControl
        self.numLines = len(lines)
        self.boxStartFraction = 0.0
        self.boxStopFraction = 0.0
        self.calcBoxFractions()

        # see if we are activated
        self.activated = True
        (maxy, maxx) = self.screenControl.getScreenDimensions()
        if (self.numLines < maxy):
            self.activated = False
            logger.addEvent('no_scrollbar')
        else:
            logger.addEvent('needed_scrollbar')
Ejemplo n.º 21
0
    def __init__(self, stdscr, lines, screenControl):
        self.stdscr = stdscr
        self.screenControl = screenControl
        self.numLines = len(lines)
        self.boxStartFraction = 0.0
        self.boxStopFraction = 0.0
        self.calcBoxFractions()

        # see if we are activated
        self.activated = True
        maxy, _ = self.screenControl.screen_dimensions
        if (self.numLines < maxy):
            self.activated = False
            logger.addEvent('no_scrollbar')
        else:
            logger.addEvent('needed_scrollbar')
Ejemplo n.º 22
0
    def __init__(self, stdscr, lines, screenControl):
        self.stdscr = stdscr
        self.screenControl = screenControl
        self.numLines = len(lines)
        self.boxStartFraction = 0.0
        self.boxStopFraction = 0.0
        self.calcBoxFractions()

        # see if we are activated
        self.activated = True
        maxy, _ = self.screenControl.screen_dimensions
        if (self.numLines < maxy):
            self.activated = False
            logger.addEvent('no_scrollbar')
        else:
            logger.addEvent('needed_scrollbar')
Ejemplo n.º 23
0
    def __init__(self, printer, lines, screenControl):
        self.printer = printer
        self.screenControl = screenControl
        self.numLines = len(lines)
        self.boxStartFraction = 0.0
        self.boxStopFraction = 0.0
        self.calcBoxFractions()

        # see if we are activated
        self.activated = True
        (maxy, maxx) = self.screenControl.getScreenDimensions()
        if (self.numLines < maxy):
            self.activated = False
            logger.addEvent('no_scrollbar')
        else:
            logger.addEvent('needed_scrollbar')
Ejemplo n.º 24
0
    def beginEnterCommand(self):
        self.stdscr.clear()
        self.mode = COMMAND_MODE
        self.helperChrome.output(self.mode)
        logger.addEvent('enter_command_mode')

        command = self.showAndGetCommand()
        if len(command) == 0:
            # go back to selection mode and repaint
            self.mode = SELECT_MODE
            curses.noecho()
            self.dirtyLines()
            logger.addEvent('exit_command_mode')
            return
        lineObjs = self.getFilesToUse()
        output.execComposedCommand(command, lineObjs)
        sys.exit(0)
Ejemplo n.º 25
0
    def beginEnterCommand(self):
        self.stdscr.clear()
        self.mode = COMMAND_MODE
        self.helperChrome.output(self.mode)
        logger.addEvent('enter_command_mode')

        command = self.showAndGetCommand()
        if len(command) == 0:
            # go back to selection mode and repaint
            self.mode = SELECT_MODE
            curses.noecho()
            self.dirtyLines()
            logger.addEvent('exit_command_mode')
            return
        lineObjs = self.getFilesToUse()
        output.execComposedCommand(command, lineObjs)
        sys.exit(0)
Ejemplo n.º 26
0
def getLineObjs():
    filePath = os.path.expanduser(PICKLE_FILE)
    lineObjs = pickle.load(open(filePath))
    matches = [lineObj for i, lineObj in lineObjs.items()
               if not lineObj.isSimple()]
    logger.addEvent('total_num_files', len(lineObjs.items()))

    selectionPath = os.path.expanduser(SELECTION_PICKLE)
    if os.path.isfile(selectionPath):
        selectedIndices = pickle.load(open(selectionPath))
        for index in selectedIndices:
            if index < len(matches):
                matches[index].setSelect(True)

    if not len(matches):
        output.writeToFile('echo "No lines matched!!"')
        sys.exit(0)
    return lineObjs
Ejemplo n.º 27
0
def getLineObjs():
    filePath = os.path.expanduser(PICKLE_FILE)
    lineObjs = pickle.load(open(filePath))
    matches = [lineObj for lineObj in lineObjs.values()
               if isinstance(lineObj, LineMatch)]
    logger.addEvent('total_num_files', len(lineObjs))

    selectionPath = os.path.expanduser(SELECTION_PICKLE)
    if os.path.isfile(selectionPath):
        selectedIndices = pickle.load(open(selectionPath))
        for index in selectedIndices:
            if index < len(matches):
                matches[index].is_selected = True

    if not matches:
        output.writeToFile('echo "No lines matched!!"')
        sys.exit(0)
    return lineObjs
Ejemplo n.º 28
0
def getLineObjs():
    filePath = stateFiles.getPickleFilePath()
    try:
        lineObjs = pickle.load(open(filePath, 'rb'))
    except:
        output.appendError(LOAD_SELECTION_WARNING)
        sys.exit(1)
    logger.addEvent('total_num_files', len(lineObjs.items()))

    selectionPath = stateFiles.getSelectionFilePath()
    if os.path.isfile(selectionPath):
        setSelectionsFromPickle(selectionPath, lineObjs)

    matches = [lineObj for i, lineObj in lineObjs.items()
               if not lineObj.isSimple()]
    if not len(matches):
        output.writeToFile('echo "No lines matched!!"')
        sys.exit(0)
    return lineObjs
Ejemplo n.º 29
0
def getLineObjs():
    filePath = stateFiles.getPickleFilePath()
    try:
        lineObjs = pickle.load(open(filePath, 'rb'))
    except:
        output.appendError(LOAD_SELECTION_WARNING)
        sys.exit(1)
    logger.addEvent('total_num_files', len(lineObjs.items()))

    selectionPath = stateFiles.getSelectionFilePath()
    if os.path.isfile(selectionPath):
        setSelectionsFromPickle(selectionPath, lineObjs)

    matches = [lineObj for i, lineObj in lineObjs.items()
               if not lineObj.isSimple()]
    if not len(matches):
        output.writeToFile('echo "No lines matched!!"')
        sys.exit(0)
    return lineObjs
Ejemplo n.º 30
0
    def __init__(self, flags, keyBindings, stdscr, lineObjs, cursesAPI):
        self.stdscr = stdscr
        self.cursesAPI = cursesAPI
        self.cursesAPI.useDefaultColors()
        self.colorPrinter = ColorPrinter(self.stdscr, cursesAPI)
        self.flags = flags
        self.keyBindings = keyBindings

        self.lineObjs = lineObjs
        self.hoverIndex = 0
        self.scrollOffset = 0
        self.scrollBar = ScrollBar(self.colorPrinter, lineObjs, self)
        self.helperChrome = HelperChrome(self.colorPrinter, self, flags)
        (self.oldmaxy, self.oldmaxx) = self.getScreenDimensions()
        self.mode = SELECT_MODE

        # lets loop through and split
        self.lineMatches = []

        for lineObj in self.lineObjs.values():
            lineObj.controller = self
            if not lineObj.isSimple():
                self.lineMatches.append(lineObj)

        # begin tracking dirty state
        self.resetDirty()

        if self.flags.args.all:
            self.toggleSelectAll()

        self.numLines = len(lineObjs.keys())
        self.numMatches = len(self.lineMatches)

        self.setHover(self.hoverIndex, True)

        # the scroll offset might not start off
        # at 0 if our first real match is WAY
        # down the screen -- so lets init it to
        # a valid value after we have all our line objects
        self.updateScrollOffset()

        logger.addEvent('init')
Ejemplo n.º 31
0
    def __init__(self, flags, keyBindings, stdscr, lineObjs, cursesAPI):
        self.stdscr = stdscr
        self.cursesAPI = cursesAPI
        self.cursesAPI.useDefaultColors()
        self.colorPrinter = ColorPrinter(self.stdscr, cursesAPI)
        self.flags = flags
        self.keyBindings = keyBindings

        self.lineObjs = lineObjs
        self.hoverIndex = 0
        self.scrollOffset = 0
        self.scrollBar = ScrollBar(self.colorPrinter, lineObjs, self)
        self.helperChrome = HelperChrome(self.colorPrinter, self, flags)
        (self.oldmaxy, self.oldmaxx) = self.getScreenDimensions()
        self.mode = SELECT_MODE

        # lets loop through and split
        self.lineMatches = []

        for lineObj in self.lineObjs.values():
            lineObj.controller = self
            if not lineObj.isSimple():
                self.lineMatches.append(lineObj)

        # begin tracking dirty state
        self.resetDirty()

        if self.flags.args.all:
            self.toggleSelectAll()

        self.numLines = len(lineObjs.keys())
        self.numMatches = len(self.lineMatches)

        self.setHover(self.hoverIndex, True)

        # the scroll offset might not start off
        # at 0 if our first real match is WAY
        # down the screen -- so lets init it to
        # a valid value after we have all our line objects
        self.updateScrollOffset()

        logger.addEvent('init')
Ejemplo n.º 32
0
def getLineObjs():
    filePath = os.path.expanduser(PICKLE_FILE)
    lineObjs = pickle.load(open(filePath))
    matches = [
        lineObj for lineObj in lineObjs.values()
        if isinstance(lineObj, LineMatch)
    ]
    logger.addEvent('total_num_files', len(lineObjs))

    selectionPath = os.path.expanduser(SELECTION_PICKLE)
    if os.path.isfile(selectionPath):
        selectedIndices = pickle.load(open(selectionPath))
        for index in selectedIndices:
            if index < len(matches):
                matches[index].is_selected = True

    if not matches:
        output.writeToFile('echo "No lines matched!!"')
        sys.exit(0)
    return lineObjs
Ejemplo n.º 33
0
def getRepoPath():
    proc = subprocess.Popen(["git rev-parse --show-toplevel"],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell=True,
                            universal_newlines=True)

    (stdout, stderr) = proc.communicate()

    # If there was no error return the output
    if not stderr:
        logger.addEvent('using_git')
        return stdout

    proc = subprocess.Popen(["hg root"],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell=True)

    (stdout, stderr) = proc.communicate()

    # If there was no error return the output
    if not stderr:
        logger.addEvent('using_hg')
        return stdout

    # Not a git or hg repo, go with ~/www as a default
    logger.addEvent('used_outside_repo')
    return './'
Ejemplo n.º 34
0
def getRepoPath():
    proc = subprocess.Popen(["git rev-parse --show-toplevel"],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell=True)

    (stdout, stderr) = proc.communicate()

    # If there was no error return the output
    if not stderr:
        logger.addEvent('using_git')
        return stdout

    proc = subprocess.Popen(["hg root"],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell=True)

    (stdout, stderr) = proc.communicate()

    # If there was no error return the output
    if not stderr:
        logger.addEvent('using_hg')
        return stdout

    # Not a git or hg repo, go with ~/www as a default
    logger.addEvent('used_outside_repo')
    return '~/www'