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')
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"
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)
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')
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'
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)
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)
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()
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')
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)
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)
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()
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')
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)
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')
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()
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)
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)
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')
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')
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)
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
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
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
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')
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
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 './'
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'