about summary refs log tree commit diff stats
path: root/html/051scenario_test.mu.html
Commit message (Expand)AuthorAgeFilesLines
* 3764 - better colors for cross-linksKartik K. Agaram2017-03-081-3/+4
* 3761Kartik K. Agaram2017-03-071-21/+22
* 3716Kartik K. Agaram2016-12-261-0/+2
* 3710Kartik K. Agaram2016-12-261-70/+70
* 3709 - line numbers in htmlKartik K. Agaram2016-12-261-73/+97
* 3569Kartik K. Agaram2016-10-231-16/+16
* 3431Kartik K. Agaram2016-09-301-1/+1
* 3395Kartik K. Agaram2016-09-171-9/+9
* 3017Kartik K. Agaram2016-05-261-15/+15
* 2812Kartik K. Agaram2016-03-271-7/+16
* 2745Kartik K. Agaram2016-03-091-1/+1
* 2744Kartik K. Agaram2016-03-091-1/+1
* 2743Kartik K. Agaram2016-03-091-16/+7
* 2611Kartik K. Agaram2015-11-291-2/+2
* 2177Kartik K. Agaram2015-09-071-24/+25
* 2175Kartik K. Agaram2015-09-061-25/+24
* 2062Kartik K. Agaram2015-08-231-1/+1
* 1885Kartik K. Agaram2015-07-291-15/+15
* 1631 - update html versionsKartik K. Agaram2015-06-231-3/+3
* 1556Kartik K. Agaram2015-06-121-1/+1
* 1549Kartik K. Agaram2015-06-091-2/+2
* 1517Kartik K. Agaram2015-05-301-3/+3
* 1461 - descriptions/table of contents for the layersKartik K. Agaram2015-05-261-1/+1
* 1459Kartik K. Agaram2015-05-251-8/+9
* 1376 - update github docsKartik K. Agaram2015-05-141-55/+55
* 1291Kartik K. Agaram2015-05-061-1/+1
* 1279 - colorized rendering of the source filesKartik K. Agaram2015-05-061-0/+103
lor: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Copyright (C) 2009-2013  Roman Zimbelmann <hut@lavabit.com>
# This software is distributed under the terms of the GNU GPL version 3.

"""
The titlebar is the widget at the top, giving you broad overview.

It displays the current path among other things.
"""

from os.path import basename

from . import Widget
from ranger.gui.bar import Bar

class TitleBar(Widget):
    old_thisfile = None
    old_keybuffer = None
    old_wid = None
    result = None
    throbber = ' '
    need_redraw = False
    tab_width = 0

    def __init__(self, *args, **keywords):
        Widget.__init__(self, *args, **keywords)
        self.fm.signal_bind('tab.change', self.request_redraw, weak=True)

    def request_redraw(self):
        self.need_redraw = True

    def draw(self):
        if self.need_redraw or \
                self.fm.thisfile != self.old_thisfile or\
                str(self.fm.ui.keybuffer) != str(self.old_keybuffer) or\
                self.wid != self.old_wid:
            self.need_redraw = False
            self.old_wid = self.wid
            self.old_thisfile = self.fm.thisfile
            self._calc_bar()
        self._print_result(self.result)
        if self.wid > 2:
            self.color('in_titlebar', 'throbber')
            self.addnstr(self.y, self.wid - 2 - self.tab_width,
                    self.throbber, 1)

    def click(self, event):
        """Handle a MouseEvent"""
        direction = event.mouse_wheel_direction()
        if direction:
            self.fm.tab_move(direction)
            self.need_redraw = True
            return True

        if not event.pressed(1) or not self.result:
            return False

        pos = self.wid - 1
        for tabname in reversed(self.fm._get_tab_list()):
            tabtext = self._get_tab_text(tabname)
            pos -= len(tabtext)
            if event.x > pos:
                self.fm.tab_open(tabname)
                self.need_redraw = True
                return True

        pos = 0
        for i, part in enumerate(self.result):
            pos += len(part)
            if event.x < pos:
                if i < 2:
                    self.fm.enter_dir("~")
                elif i == 2:
                    self.fm.enter_dir("/")
                else:
                    try:
                        self.fm.enter_dir(part.directory)
                    except:
                        pass
                return True
        return False

    def _calc_bar(self):
        bar = Bar('in_titlebar')
        self._get_left_part(bar)
        self._get_right_part(bar)
        try:
            bar.shrink_from_the_left(self.wid)
        except ValueError:
            bar.shrink_by_removing(self.wid)
        self.result = bar.combine()

    def _get_left_part(self, bar):
        # TODO: Properly escape non-printable chars without breaking unicode
        if self.fm.username == 'root':
            clr = 'bad'
        else:
            clr = 'good'

        bar.add(self.fm.username, 'hostname', clr, fixed=True)
        bar.add('@', 'hostname', clr, fixed=True)
        bar.add(self.fm.hostname, 'hostname', clr, fixed=True)
        bar.add(':', 'hostname', clr, fixed=True)

        pathway = self.fm.thistab.pathway
        if self.settings.tilde_in_titlebar and \
                self.fm.thisdir.path.startswith(self.fm.home_path):
            pathway = pathway[self.fm.home_path.count('/')+1:]
            bar.add('~/', 'directory', fixed=True)

        for path in pathway:
            if path.is_link:
                clr = 'link'
            else:
                clr = 'directory'

            bar.add(path.basename, clr, directory=path)
            bar.add('/', clr, fixed=True, directory=path)

        if self.fm.thisfile is not None:
            bar.add(self.fm.thisfile.basename, 'file')

    def _get_right_part(self, bar):
        # TODO: fix that pressed keys are cut off when chaining CTRL keys
        kb = str(self.fm.ui.keybuffer)
        self.old_keybuffer = kb
        bar.addright(kb, 'keybuffer', fixed=True)
        bar.addright('  ', 'space', fixed=True)
        self.tab_width = 0
        if len(self.fm.tabs) > 1:
            for tabname in self.fm._get_tab_list():
                tabtext = self._get_tab_text(tabname)
                self.tab_width += len(tabtext)
                clr = 'good' if tabname == self.fm.current_tab else 'bad'
                bar.addright(tabtext, 'tab', clr, fixed=True)

    def _get_tab_text(self, tabname):
        result = ' ' + str(tabname)
        if self.settings.dirname_in_tabs:
            dirname = basename(self.fm.tabs[tabname].path)
            if not dirname:
                result += ":/"
            elif len(dirname) > 15:
                result += ":" + dirname[:14] + "~"
            else:
                result += ":" + dirname
        return result

    def _print_result(self, result):
        self.win.move(0, 0)
        for part in result:
            self.color(*part.lst)
            y, x = self.win.getyx()
            self.addstr(y, x, str(part))
        self.color_reset()