Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/__tests__/expected/gitDiffWithPageDown.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
.
.
. ___________________________________________________________________________
=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] comman
=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick
2 changes: 1 addition & 1 deletion src/__tests__/expected/gitDiffWithPageDownColor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@

. ___________________________________________________________________________

=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] comman
=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick

2 changes: 1 addition & 1 deletion src/__tests__/expected/gitDiffWithScroll.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
.
.
. ___________________________________________________________________________
=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] comman
=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick
2 changes: 1 addition & 1 deletion src/__tests__/expected/gitDiffWithScrollUp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
/-\
\-/
. ___________________________________________________________________________
=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] comman
=== [f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick
2 changes: 1 addition & 1 deletion src/__tests__/expected/gitDiffWithValidation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ ___________________

________________________________________________________________________________

[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec

2 changes: 1 addition & 1 deletion src/__tests__/expected/selectCommandWithPassedCommand.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Press any key to go back to selecting files.


________________________________________________________________________________
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec
2 changes: 1 addition & 1 deletion src/__tests__/expected/selectDownSelect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@


________________________________________________________________________________
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec
2 changes: 1 addition & 1 deletion src/__tests__/expected/selectDownSelectInverse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@


________________________________________________________________________________
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec
2 changes: 1 addition & 1 deletion src/__tests__/expected/selectFirst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@


________________________________________________________________________________
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec
2 changes: 1 addition & 1 deletion src/__tests__/expected/simpleLoadAndQuit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@


________________________________________________________________________________
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec
2 changes: 1 addition & 1 deletion src/__tests__/expected/simpleSelectWithAttributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@

________________________________________________________________________________

[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec

2 changes: 1 addition & 1 deletion src/__tests__/expected/simpleSelectWithColor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@

________________________________________________________________________________________________________________________________________________________________________________________________________

[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mode
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick select mode, [c] command mode

2 changes: 1 addition & 1 deletion src/__tests__/expected/simpleWithAttributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@

________________________________________________________________________________

[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mod
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick selec

2 changes: 1 addition & 1 deletion src/__tests__/expected/tallLoadAndQuit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@


____________________________________________________________________________________________________________________________________________
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mode
[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick select mode, [c] command mode
44 changes: 39 additions & 5 deletions src/screenControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import usageStrings
import output
import logger
import format
from charCodeMapping import CODE_TO_CHAR
from colorPrinter import ColorPrinter

Expand All @@ -30,8 +31,11 @@ def signal_handler(signal, frame):

SELECT_MODE = 'SELECT'
COMMAND_MODE = 'COMMAND_MODE'
X_MODE = 'X_MODE'

SHORT_NAV_USAGE = '[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [c] command mode'
lbls = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*()_+<>?{}|;'"

SHORT_NAV_USAGE = '[f|A] selection, [down|j|up|k|space|b] navigation, [enter] open, [x] quick select mode, [c] command mode'
SHORT_COMMAND_USAGE = 'command examples: | git add | git checkout HEAD~1 -- | mv $F ../here/ |'
SHORT_COMMAND_PROMPT = 'Type a command below! Files will be appended or replace $F'
SHORT_COMMAND_PROMPT2 = 'Enter a blank line to go back to the selection process'
Expand Down Expand Up @@ -109,7 +113,11 @@ def outputBottom(self):
(maxy, maxx) = self.screenControl.getScreenDimensions()
borderY = maxy - 2
# first output text since we might throw an exception during border
usageStr = SHORT_NAV_USAGE if self.mode == SELECT_MODE else SHORT_COMMAND_USAGE
usageStr = {
SELECT_MODE: SHORT_NAV_USAGE,
X_MODE: SHORT_NAV_USAGE,
COMMAND_MODE: SHORT_COMMAND_USAGE
}[self.mode]
borderStr = '_' * (maxx - self.getMinX() - 0)
self.printer.addstr(borderY, self.getMinX(), borderStr)
self.printer.addstr(borderY + 1, self.getMinX(), usageStr)
Expand Down Expand Up @@ -245,7 +253,8 @@ def getScreenDimensions(self):

def getChromeBoundaries(self):
(maxy, maxx) = self.stdscr.getmaxyx()
minx = CHROME_MIN_X if self.scrollBar.getIsActivated() else 0
minx = CHROME_MIN_X if self.scrollBar.getIsActivated(
) or self.mode == X_MODE else 0
maxy = self.helperChrome.reduceMaxY(maxy)
maxx = self.helperChrome.reduceMaxX(maxx)
# format of (MINX, MINY, MAXX, MAXY)
Expand Down Expand Up @@ -348,6 +357,8 @@ def processInput(self, key):
self.moveIndex(-1)
elif key == 'DOWN' or key == 'j':
self.moveIndex(1)
elif key == 'x':
self.toggleXMode()
elif key == 'c':
self.beginEnterCommand()
elif key == ' ' or key == 'PAGE_DOWN':
Expand All @@ -356,11 +367,11 @@ def processInput(self, key):
self.pageUp()
elif key == 'g':
self.jumpToIndex(0)
elif key == 'G':
elif key == 'G' and not self.mode == X_MODE:
self.jumpToIndex(self.numMatches - 1)
elif key == 'f':
self.toggleSelect()
elif key == 'A':
elif key == 'A' and not self.mode == X_MODE:
self.toggleSelectAll()
elif key == 'ENTER':
self.onEnter()
Expand All @@ -370,6 +381,8 @@ def processInput(self, key):
# before exiting the program
self.getFilesToUse()
self.cursesAPI.exit()
elif self.mode == X_MODE and key in lbls:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might prone to breakage in the future since we might add keys above this statement that are in lbls and forget about X_MODE. i wonder if we could instead refactor some of this...

self.selectXMode(key)
pass

def getFilesToUse(self):
Expand Down Expand Up @@ -529,6 +542,7 @@ def printAll(self):
self.stdscr.erase()
self.printLines()
self.printScroll()
self.printXMode()
self.printChrome()

def printLines(self):
Expand Down Expand Up @@ -561,3 +575,23 @@ def moveCursor(self):
def getKey(self):
charCode = self.stdscr.getch()
return CODE_TO_CHAR.get(charCode, '')

def toggleXMode(self):
self.mode = X_MODE if self.mode != X_MODE else SELECT_MODE
self.printAll()

def printXMode(self):
if self.mode == X_MODE:
(maxy, _) = self.scrollBar.screenControl.getScreenDimensions()
topY = maxy - 2
minY = self.scrollBar.getMinY() - 1
for i in range(minY, topY + 1):
self.stdscr.addstr(i, 1, lbls[i - minY])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah using color printer here would be nice


def selectXMode(self, key):
lineObj = self.lineObjs[
lbls.index(key) - self.scrollOffset]
if type(lineObj) == format.LineMatch:
lineMatchIndex = self.lineMatches.index(lineObj)
self.hoverIndex = lineMatchIndex
self.toggleSelect()