Example #1
0
	def show_help( self, wait_for_input ):
		self.set_status_line( _("Press any key to continue"), False )

		self.textwindow.erase()

		line_num = self.win_height - 4
		for line in COPYRIGHT_MESSAGES:
			newline = line.center( self.win_width )
			self.textwindow.addnstr( line_num, 0,
				newline, self.win_width, self.CP_NORMAL )
			line_num += 1

		for line_num, line in enumerate( HELP_MESSAGES ):
			if isinstance( line, str ):
				newline = line.center( self.win_width )
			else:
				newline = "%%0%ds - %%s" % ( self.win_width // 2 )
				newline = newline % ( line[0], line[1] )
			self.textwindow.addnstr( line_num, 0,
				newline, self.win_width, self.CP_NORMAL )

		self.textwindow.refresh()
		if wait_for_input:
			self.textwindow.getch()
			self.set_status_line( self.DEFAULT_STATUS_MESSAGE, False )
			self.draw_screen()
Example #2
0
	def next_difference( self, direction ):

		line, current_pos = self.get_line_of_next_diff( direction )

		# If there are no more differences, we have
		# nothing to do
		if line is None:
			this_line_status = self.lines[self.mycursor.line_num].status
			if direction > 0:
				if this_line_status == difflinetypes.IDENTICAL:
					return _("After last difference")
				else:
					return _("At last difference")
			else:
				if this_line_status == difflinetypes.IDENTICAL:
					return _("Before first difference")
				else:
					return _("At first difference")

		next_line_pos = self.get_line_of_end_of_diff(
			direction, line, current_pos )

		if direction < 0:
			# If we're going backwards, we jump to the
			# beginning of this difference
			current_pos = next_line_pos
			if current_pos <= self.top_line:
				scroll = True
			else:
				scroll = False
		else:
			if next_line_pos >= ( self.bot_line - 1 ):
				scroll = True
			else:
				scroll = False

		if scroll:
			self.scroll_to_line( current_pos )
		else:
			self.move_cursor_and_refresh( current_pos - self.top_line, False )
Example #3
0
	def __init__( self, diffmodel, filename_left=None, filename_right=None,
			filemanager=None ):
		self.diffmodel = diffmodel
		self.filename_left = filename_left
		self.filename_right = filename_right
		self.filemanager = filemanager
		self.top_line = 0
		self.bot_line = None
		self.first_col = 0
		self.mycursor = NCursesView.Cursor( directions.LEFT, 0 )
		self.win_height = None # Modify these in test code
		self.win_width = None  #
		self.DEFAULT_STATUS_MESSAGE = _("Press SHIFT-H for help")
	def run( self, debug_actions ):

		self.v.set_status_line( _("Editing line.  Press ESC to finish."), True )
		self.v.mycursor.column_status = cursor_column_state.COLUMN_SINGLE
		self.v.refresh_cursor_line()

		if debug_actions is None:
			self.main_loop()
		else:
			for action in debug_actions:
				if isinstance( action, str ):
					action = ord( action )
				keep_going = self.process_keypress( action )
				if not keep_going:
					break
			else:
				return -1

		self.v.mycursor.column_status = cursor_column_state.COLUMN_ALL
		self.v.refresh_cursor_line()
		self.v.set_status_line( self.v.DEFAULT_STATUS_MESSAGE, False )
Example #5
0
	def process_keypress( self, key, remaining_dbg_acts=None,
			wait_for_input=True ):

		status_line = -1

		keep_going = True

		if key == ord( "q" ): # Quit
			keep_going = False

		elif key == ord( "h" ) or key == curses.KEY_LEFT:
			status_line = self.move_cursor( directions.LEFT, False )
		elif key == ord( "l" ) or key == curses.KEY_RIGHT:
			status_line = self.move_cursor( directions.RIGHT, False )

		elif key == ord( "j" ) or key == curses.KEY_DOWN:
			status_line = self.move_cursor( directions.DOWN, False )
		elif key == ord( "k" ) or key == curses.KEY_UP:
			status_line = self.move_cursor( directions.UP, False )

		elif key == ord( "[" ): # Copy lines right to left
			status_line = self.copy_lines( directions.LEFT )
		elif key == ord( "]" ): # Copy lines left to right
			status_line = self.copy_lines( directions.RIGHT )

		elif key == ord( "a" ): # Add a line
			status_line = self.add_line()

		elif key == ord( "d" ): # Delete selected lines
			status_line = self.delete_lines()

		# Edit mode disabled
		#elif key == ord( "e" ): # Edit mode
		#	status_line = NCursesViewEditMode( self ).run( remaining_dbg_acts )

		elif key == ord( "J" ): # Extend selection down
			status_line = self.move_cursor( directions.DOWN, True )
		elif key == ord( "K" ): # Extend selection up
			status_line = self.move_cursor( directions.UP, True )

		elif key == ord( "." ) or key == curses.KEY_NPAGE: # Page down
			status_line = self.change_page( 1, False )
		elif key == ord( "," ) or key == curses.KEY_PPAGE: # Page up
			status_line = self.change_page( -1, False )

		elif key == ord( ">" ): # Extend selection 1 page down
			status_line = self.change_page( 1, True )
		elif key == ord( "<" ): # Extend selection 1 page up
			status_line = self.change_page( -1, True )

		elif key == ord( "n" ) or key == curses.KEY_F8: # Next difference
			status_line = self.next_difference( 1 )
		elif key == ord( "p" ) or key == curses.KEY_F7: # Previous difference
			status_line = self.next_difference( -1 )

		elif key == ord( "z" ): # Scroll left
			status_line = self.scroll_horizontal( -1 )
		elif key == ord( "x" ): # Scroll right
			status_line = self.scroll_horizontal( 1 )

		elif key == ord( "s" ): # Save
			assert( self.filemanager )
			status = self.filemanager.save( self.diffmodel, self.mycursor.lr )
			if status == save_status.STATUS_SAVED:
				self.diffmodel.set_save_point( self.mycursor.lr )
				self.set_status_line( _("File saved."), True )
				self.draw_header_window()
				self.set_top_line( self.top_line )
				self.draw_screen()
			elif status == save_status.STATUS_NOCHANGES:
				self.set_status_line( _("No changes were made in this file."),
					True )

		elif key == ord( "H" ): # Help
			self.show_help( wait_for_input )
			# We have already reset the status after showing the help
			status_line = -1

		if status_line is None:
			self.set_status_line( self.DEFAULT_STATUS_MESSAGE, False )
		elif status_line == -1:
			pass # An unused key was pressed
		else:
			self.set_status_line( status_line )

		return keep_going
Example #6
0
import itertools

from lib.misc.constants import cursor_column_state
from lib.misc.constants import difflinetypes
from lib.misc.constants import directions
from lib.misc.constants import save_status

from lib.misc.translation import _

from lib.views.ncursesvieweditmode import NCursesViewEditMode

NEXT_DIFF_MARGIN = 3

HELP_MESSAGES = [
	"",
	_("Diffident Help"),
	"",
	( _("Quit"), _("q") ),
	( _("Move left/right"), _("h/l or Arrow Keys") ),
	( _("Move up/down"), _("k/j or Arrow Keys") ),
	( _("Select line up/down"), _("K/J") ),
	( _("Next/Previous difference"), _("n/p or F8/F7") ),
	( _("Page up/down"), _(",/. or PageUp/Down") ),
	( _("Select page up/down"), _("</>") ),
	( _("Scroll left/right"), _("z/x") ),
	( _("Copy left/right"), _("[/]") ),
	( _("Insert line"), _("a") ),
	( _("Delete line(s)"), _("d") ),
	( _("Save changes"), _("s") ),
]