Пример #1
0
def legacy_main() -> None:
    print('Press any keys - Ctrl-D will terminate this program',
          end='\r\n',
          flush=True)
    print(styled('UNIX', italic=True, fg='green'),
          styled('send_text', italic=True, fg='green'),
          sep='\t\t',
          end='\r\n')

    with raw_mode():
        read_keys()
Пример #2
0
 def open_url(self, url: str, hyperlink_id: int, cwd: Optional[str] = None) -> None:
     if hyperlink_id:
         if not self.opts.allow_hyperlinks:
             return
         from urllib.parse import unquote, urlparse, urlunparse
         try:
             purl = urlparse(url)
         except Exception:
             return
         if (not purl.scheme or purl.scheme == 'file'):
             if purl.netloc:
                 from socket import gethostname
                 try:
                     hostname = gethostname()
                 except Exception:
                     hostname = ''
                 remote_hostname = purl.netloc.partition(':')[0]
                 if remote_hostname and remote_hostname != hostname and remote_hostname != 'localhost':
                     self.handle_remote_file(purl.netloc, unquote(purl.path))
                     return
                 url = urlunparse(purl._replace(netloc=''))
         if self.opts.allow_hyperlinks & 0b10:
             from kittens.tui.operations import styled
             get_boss()._run_kitten('ask', ['--type=choices', '--message', _(
                 'What would you like to do with this URL:\n') +
                 styled(unquote(url), fg='yellow'),
                 '--choice=o:Open', '--choice=c:Copy to clipboard', '--choice=n;red:Nothing'
                 ],
                 window=self,
                 custom_callback=partial(self.hyperlink_open_confirmed, url, cwd)
             )
             return
     get_boss().open_url(url, cwd=cwd)
Пример #3
0
 def draw_screen(self):
     """ Draws the UI """
     self.cmd.clear_screen()
     self.print(
         styled("Available Colorschemes:", bold=True, fg="gray", fg_intense=True)
     )
     self.print()
     self.print(styled(self.opts.theme_path, fg="gray"))
     self.print()
     for i in range(len(self.themes)):
         self.print(
             "  {} {}".format(
                 styled(self.letters[i], fg="green"),
                 styled(self.themes[i].split("/")[-1].split(".")[0], fg="blue"),
             )
         )
     self.print()
     self.print("{} To quit".format(styled("ESC", fg="red")))
Пример #4
0
 def draw_screen(self):
     self.write(clear_screen())
     if self.window_ids:
         input_text = self.line_edit.current_input
         if self.text_marked:
             self.line_edit.current_input = styled(input_text, reverse=True)
         self.line_edit.write(self.write, self.prompt)
         self.line_edit.current_input = input_text
     if self.error:
         with cursor(self.write):
             self.print('')
             for l in self.error.split('\n'):
                 self.print(l)
Пример #5
0
def print_key(raw: bytearray) -> None:
    unix = ''
    for ch in raw:
        if ch < len(ctrl_keys):
            unix += f'^{ctrl_keys[ch]}'
        elif ch == 127:
            unix += '^?'
        else:
            unix += chr(ch)
    print(unix + '\t\t', end='')
    for ch in raw:
        x = chr(ch).encode('utf-8')
        print(styled(repr(x)[2:-1], fg='yellow'), end='')
    print(end='\r\n', flush=True)
Пример #6
0
def compare_opts(opts: KittyOpts, print: Print) -> None:
    from .config import load_config
    print()
    print('Config options different from defaults:')
    default_opts = load_config()
    ignored = ('keymap', 'sequence_map', 'mousemap', 'map', 'mouse_map')
    changed_opts = [
        f for f in sorted(defaults._fields)
        if f not in ignored and getattr(opts, f) != getattr(defaults, f)
    ]
    field_len = max(map(len, changed_opts)) if changed_opts else 20
    fmt = f'{{:{field_len:d}s}}'
    colors = []
    for f in changed_opts:
        val = getattr(opts, f)
        if isinstance(val, dict):
            print(title(f'{f}:'))
            if f == 'symbol_map':
                for k in sorted(val):
                    print(f'\tU+{k[0]:04x} - U+{k[1]:04x} → {val[k]}')
            elif f == 'modify_font':
                for k in sorted(val):
                    print('   ', val[k])
            else:
                print(pformat(val))
        else:
            val = getattr(opts, f)
            if isinstance(val, Color):
                colors.append(
                    fmt.format(f) + ' ' + color_as_sharp(val) + ' ' +
                    styled('  ', bg=val))
            else:
                print(fmt.format(f), str(getattr(opts, f)))

    compare_maps(opts.mousemap, default_opts.mousemap, print)
    final_, initial_ = opts.keymap, default_opts.keymap
    final: ShortcutMap = {Shortcut((k, )): v for k, v in final_.items()}
    initial: ShortcutMap = {Shortcut((k, )): v for k, v in initial_.items()}
    final_s, initial_s = map(flatten_sequence_map,
                             (opts.sequence_map, default_opts.sequence_map))
    final.update(final_s)
    initial.update(initial_s)
    compare_maps(final, initial, print)
    if colors:
        print(f'{title("Colors")}:', end='\n\t')
        print('\n\t'.join(sorted(colors)))
Пример #7
0
 def draw_screen(self) -> None:
     self.cmd.clear_screen()
     print = self.print
     print(styled(self.msg, bold=True, fg="gray", fg_intense=True))
     print()
     for item in self.selection:
         if item == self.selected:
             to_print = styled(item, bg="yellow", fg="black")
         else:
             to_print = item
         print(f"   {to_print}")
     print()
     print("↑: {}".format(styled("Up/K", italic=True)))
     print("↓: {}".format(styled("Down/J", italic=True)))
     print("Select: {}".format(styled("Enter", italic=True)))
     print("Exit: {}".format(styled("Esc/Q", italic=True)))
Пример #8
0
 def penv(k: str) -> None:
     v = os.environ.get(k)
     if v is not None:
         p('\t' + k.ljust(35), styled(v, dim=True))