def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if PY3: if self.question_queue: umax = len(self.question_queue[0][0]) + 1 - self.wid else: umax = len(self.line) + 1 self.pos = direction.move(direction=direction.right(), minimum=0, maximum=umax, current=self.pos) else: if self.question_queue: uchar = list(self.question_queue[0][0].decode( 'utf-8', 'ignore')) upos = len(self.question_queue[0][0][:self.pos].decode( 'utf-8', 'ignore')) umax = len(uchar) + 1 - self.wid else: uchar = list(self.line.decode('utf-8', 'ignore')) upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) umax = len(uchar) + 1 newupos = direction.move(direction=direction.right(), minimum=0, maximum=umax, current=upos) self.pos = len(''.join(uchar[:newupos]).encode( 'utf-8', 'ignore'))
def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move(direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): movement = dict(direction=direction.down(), override=narg, current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1) if self.source_is_stream: # For streams, we first pretend that the content ends much later, # in case there are still unread lines. desired_position = direction.move(maximum=len(self.lines) + 9999, **movement) # Then, read the new lines as needed to produce a more accurate # maximum for the movement: self._get_line(desired_position + self.hei) self.scroll_begin = direction.move(maximum=len(self.lines), **movement)
def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move( direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): movement = dict( direction=direction.down(), override=narg, current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1) if self.source_is_stream: # For streams, we first pretend that the content ends much later, # in case there are still unread lines. desired_position = direction.move( maximum=len(self.lines) + 9999, **movement) # Then, read the new lines as needed to produce a more accurate # maximum for the movement: self._get_line(desired_position + self.hei) self.scroll_begin = direction.move( maximum=len(self.lines), **movement)
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: if self.question_queue: umax = len(self.question_queue[0][0]) + 1 - self.wid else: umax = len(self.line) + 1 self.pos = direction.move( direction=direction.right(), minimum=0, maximum=umax, current=self.pos) else: if self.question_queue: uchar = list(self.question_queue[0][0].decode('utf-8', 'ignore')) upos = len(self.question_queue[0][0][:self.pos].decode('utf-8', 'ignore')) umax = len(uchar) + 1 - self.wid else: uchar = list(self.line.decode('utf-8', 'ignore')) upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) umax = len(uchar) + 1 newupos = direction.move( direction=direction.right(), minimum=0, maximum=umax, current=upos) self.pos = len(''.join(uchar[:newupos]).encode('utf-8', 'ignore'))
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: self.pos = direction.move( direction=direction.right(), minimum=0, maximum=len(self.line) + 1, current=self.pos ) else: uc = uchars(self.line) upos = len(uchars(self.line[: self.pos])) newupos = direction.move(direction=direction.right(), minimum=0, maximum=len(uc) + 1, current=upos) self.pos = len("".join(uc[:newupos]))
def execute(self): if not self.fm.ui.pager.visible or not self.fm.thisfile or not self.fm.thisfile.is_file: return try: kw = {self.arg(1): int(self.arg(2))} except ValueError: k, v = self.arg(-1).split('=') kw = {k: int(v)} kw.setdefault('cycle', self.fm.settings['wrap_scroll']) kw.setdefault('one_indexed', self.fm.settings['one_indexed']) direction = Direction(kw) if not direction.vertical(): return cwd = self.fm.thisdir pos_orgin = cwd.pointer while True: old_thisfile = self.fm.thisfile cwd.pointer = direction.move( direction=direction.down(), maximum=len(cwd), current=cwd.pointer, pagesize=self.fm.ui.browser.hei) cwd.correct_pointer() if self.fm.thisfile.is_directory: if old_thisfile == self.fm.thisfile: cwd.pointer = pos_orgin cwd.correct_pointer() break else: break if pos_orgin != cwd.pointer: self.fm.display_file()
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: self.pos = direction.move(direction=direction.right(), minimum=0, maximum=len(self.line) + 1, current=self.pos) else: uc = uchars(self.line) upos = len(uchars(self.line[:self.pos])) newupos = direction.move(direction=direction.right(), minimum=0, maximum=len(uc) + 1, current=upos) self.pos = len(''.join(uc[:newupos]))
def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move(direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): if self.source_is_stream: self._get_line(self.scroll_begin + self.hei * 2) self.scroll_begin = direction.move(direction=direction.down(), override=narg, maximum=len(self.lines), current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1)
def move(self, narg=None, **kw): direction = Direction(kw) if direction.horizontal(): self.startx = direction.move( direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): if self.source_is_stream: self._get_line(self.scroll_begin + self.hei * 2) self.scroll_begin = direction.move( direction=direction.down(), override=narg, maximum=len(self.lines), current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1)
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: self.pos = direction.move(direction=direction.right(), minimum=0, maximum=len(self.line) + 1, current=self.pos) else: if self.fm.py3: uchar = list(self.line) upos = len(self.line[:self.pos]) else: uchar = list(self.line.decode('utf-8', 'ignore')) upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) newupos = direction.move(direction=direction.right(), minimum=0, maximum=len(uchar) + 1, current=upos) self.pos = len(''.join(uchar[:newupos]).encode( 'utf-8', 'ignore'))
def move(self, narg=None, **keywords): direction = Direction(keywords) lst = self.get_list() if not lst: return self.pointer pointer = direction.move(direction=direction.down(), maximum=len(lst), override=narg, pagesize=self.get_height(), current=self.pointer) self.pointer = pointer self.correct_pointer() return pointer
def move(self, **keywords): direction = Direction(keywords) if direction.horizontal(): # Ensure that the pointer is moved utf-char-wise if self.fm.py3: self.pos = direction.move( direction=direction.right(), minimum=0, maximum=len(self.line) + 1, current=self.pos) else: if self.fm.py3: uc = list(self.line) upos = len(self.line[:self.pos]) else: uc = list(self.line.decode('utf-8', 'ignore')) upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) newupos = direction.move( direction=direction.right(), minimum=0, maximum=len(uc) + 1, current=upos) self.pos = len(''.join(uc[:newupos]).encode('utf-8', 'ignore'))
def move(self, narg=None, **keywords): direction = Direction(keywords) lst = self.get_list() if not lst: return self.pointer pointer = direction.move( direction=direction.down(), maximum=len(lst), override=narg, pagesize=self.get_height(), current=self.pointer) self.pointer = pointer self.correct_pointer() return pointer
def test_move(self): d = Direction(pages=True) self.assertEqual(3, d.move(direction=3)) self.assertEqual(5, d.move(direction=3, current=2)) self.assertEqual(15, d.move(direction=3, pagesize=5)) self.assertEqual(9, d.move(direction=3, pagesize=5, maximum=10)) self.assertEqual(18, d.move(direction=9, override=2)) d2 = Direction(absolute=True) self.assertEqual(5, d2.move(direction=9, override=5))
def move(self, narg=None, **kw): """ A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=1, percentage=True) # moves to 80% """ cwd = self.env.cwd direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except: return self.env.enter_dir(directory) if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.env.cf selection = self.env.get_selection() if not self.env.enter_dir(cf) and selection: if self.execute_file(selection, mode=mode) is False: self.open_console('open_with ') elif direction.vertical() and cwd.files: newpos = direction.move( direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos)
def move(self, narg=None, **kw): """ A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=1, percentage=True) # moves to 80% """ cwd = self.env.cwd direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except: return self.env.enter_dir(directory) if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.env.cf selection = self.env.get_selection() if not self.env.enter_dir(cf) and selection: if self.execute_file(selection, mode=mode) is False: self.open_console('open_with ') elif direction.vertical(): newpos = direction.move(direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos)
def move(self, narg=None, **kw): """A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=1, percentage=True) # moves to 80% """ cwd = self.thisdir direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except: return self.thistab.enter_dir(directory) self.change_mode('normal') if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.thisfile selection = self.thistab.get_selection() if not self.thistab.enter_dir(cf) and selection: result = self.execute_file(selection, mode=mode) if result in (False, ASK_COMMAND): self.open_console('open_with ') elif direction.vertical() and cwd.files: newpos = direction.move( direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos) if self.mode == 'visual': try: startpos = cwd.index(self._visual_start) except: self._visual_start = None startpos = min(self._visual_start_pos, len(cwd)) # The files between here and _visual_start_pos targets = set(cwd.files[min(startpos, newpos):\ max(startpos, newpos) + 1]) # The selection before activating visual mode old = self._previous_selection # The current selection current = set(cwd.marked_items) # Set theory anyone? if not self._visual_reverse: for f in targets - current: cwd.mark_item(f, True) for f in current - old - targets: cwd.mark_item(f, False) else: for f in targets & current: cwd.mark_item(f, False) for f in old - current - targets: cwd.mark_item(f, True) if self.ui.pager.visible: self.display_file()
def move(self, narg=None, **kw): """A universal movement method. Accepts these parameters: (int) down, (int) up, (int) left, (int) right, (int) to, (bool) absolute, (bool) relative, (bool) pages, (bool) percentage to=X is translated to down=X, absolute=True Example: self.move(down=4, pages=True) # moves down by 4 pages. self.move(to=2, pages=True) # moves to page 2. self.move(to=80, percentage=True) # moves to 80% """ cwd = self.thisdir direction = Direction(kw) if 'left' in direction or direction.left() > 0: steps = direction.left() if narg is not None: steps *= narg try: directory = os.path.join(*(['..'] * steps)) except Exception: return self.thistab.enter_dir(directory) self.change_mode('normal') if cwd and cwd.accessible and cwd.content_loaded: if 'right' in direction: mode = 0 if narg is not None: mode = narg cf = self.thisfile selection = self.thistab.get_selection() if not self.thistab.enter_dir(cf) and selection: result = self.execute_file(selection, mode=mode) if result in (False, ASK_COMMAND): self.open_console('open_with ') elif direction.vertical() and cwd.files: newpos = direction.move( direction=direction.down(), override=narg, maximum=len(cwd), current=cwd.pointer, pagesize=self.ui.browser.hei) cwd.move(to=newpos) if self.mode == 'visual': try: startpos = cwd.index(self._visual_start) except Exception: self._visual_start = None startpos = min(self._visual_start_pos, len(cwd)) # The files between here and _visual_start_pos targets = set(cwd.files[min(startpos, newpos): max(startpos, newpos) + 1]) # The selection before activating visual mode old = self._previous_selection # The current selection current = set(cwd.marked_items) # Set theory anyone? if not self._visual_reverse: for f in targets - current: cwd.mark_item(f, True) for f in current - old - targets: cwd.mark_item(f, False) else: for f in targets & current: cwd.mark_item(f, False) for f in old - current - targets: cwd.mark_item(f, True) if self.ui.pager.visible: self.display_file()