コード例 #1
0
    def test_build_shortcut(self):
        kaa.app.DEFAULT_THEME = 'basic'

        doc = self._getdoc('')

        doc.mode.themes = [{'basic': [
            Style('default', 'default', 'default', False, False),
            Style('shortcut', 'default', 'default', False, False),
        ]}]
        doc.mode._build_theme()

        f = dialogmode.FormBuilder(doc)

        def cb(wnd):
            pass
        f.append_text('default', 'ab&cdef', on_shortcut=cb,
                      shortcut_style='shortcut', shortcut_mark='mark1')

        assert doc.gettext(0, doc.endpos()) == 'abcdef'

        id1 = doc.mode.get_styleid('default')
        id2 = doc.mode.get_styleid('shortcut')
        assert doc.styles.getints(
            0, doc.endpos()) == [id1, id1, id2, id1, id1, id1]
        assert doc.marks['mark1'] == 2
コード例 #2
0
                if value == self.infos[name]:
                    updated = False

            self.infos[name] = value

            self.updated = self.updated or updated
            ret = ret or updated
        return ret

    def get_info(self, name, default=None):
        return self.infos.get(name, default)


StatusBarThemes = {
    'basic': [
        Style('default', 'Red', 'Base02'),
        Style('filename', 'LightBlue', 'Base02'),
        Style('msg', 'Red', 'Base02'),
        Style('editmode', 'Green', 'Base02', rjust=True),
    ],
}


class StatusBarMode(modebase.ModeBase):
    USE_UNDO = False

    def __init__(self):
        super().__init__()
        self.statusinfo = StatusInfo()

    def init_themes(self):
コード例 #3
0
ファイル: theme.py プロジェクト: smorin/kaa
from kaa.theme import Overlay
from kaa.theme import Style

DefaultThemes = {
    'basic': [
        Style('default', 'default', 'default'),
        Style('lineno', 'White', 'Blue'),
        Style('blank-line-header', 'Blue', None),
        Style('parenthesis_cur', 'White', 'Blue'),
        Style('parenthesis_match', 'Red', 'Yellow'),

        Style('keyword', 'Magenta', None),
        Style('constant', 'Red', None),
        Style('directive', 'Orange', None),
        Style('comment', 'Cyan', None),
        Style('string', 'Blue', None),
        Style('number', 'Green', None),


        Overlay('cursor-row', None, 'Base02'),
        Overlay('breakpoint', None, 'Base02'),
        Overlay('current-row', None, 'Yellow'),
    ],
}
コード例 #4
0
ファイル: msgboxmode.py プロジェクト: smorin/kaa
import unicodedata
import re
import kaa
from kaa import document
from kaa.ui.dialog import dialogmode
from kaa.theme import Style

MsgBoxThemes = {
    'basic': [
        Style('underline', 'Base3', 'Base02', underline=True),
        Style('separator', 'LightBlue', 'Base02', nowrap=False),
        Style('button', 'LightBlue', 'Base02', nowrap=True),
        Style('button.shortcut',
              'LightBlue',
              'Base02',
              underline=True,
              nowrap=True),
    ],
}


class MsgBoxMode(dialogmode.DialogMode):
    autoshrink = True
    SEPARATOR = '/'
    USE_UNDO = False
    DELAY_STR = False

    def init_themes(self):
        super().init_themes()
        self.themes.append(MsgBoxThemes)
コード例 #5
0
        if not nfiles:
            s = 'Cannot find file `{}`.'.format(option.filenames)
            doc.append(s)
        elif not nhits:
            s = 'Cannot find `{}`.'.format(option.text)
            doc.append(s)
        else:
            s = 'Found {} times in {} files'.format(nhits, nfiles)

    kaa.app.messagebar.set_message(s)

    if not target:
        kaa.app.show_doc(doc)
    else:
        target.activate()


GrepThemes = {
    'basic': [
        Style('grep-match', 'Orange', None),
    ],
}


class GrepMode(filenameindexmode.FilenameIndexMode):
    MODENAME = 'Grep'

    def init_themes(self):
        super().init_themes()
        self.themes.append(GrepThemes)
コード例 #6
0
from kaa.keyboard import *
from kaa.filetype.python import pythonmode
from kaa.command import commandid
from kaa.command import norec
from kaa.command import norerun
from kaa.theme import Style

pythonconsole_keys = {
    ('\r'): 'pythonconsole.newline',
    (alt, '\r'): 'pythonconsole.script-history',
    (alt, '\n'): 'pythonconsole.script-history',
}

PythonConsoleThemes = {
    'basic': [
        Style('stdout', 'Orange', 'Default'),
        Style('stderr', 'Magenta', 'Default'),
        Style('ps', 'Blue', 'Default'),
    ],
}


class KaaInterpreter(code.InteractiveInterpreter):
    localdict = {"__name__": "__console__", "__doc__": None}

    def __init__(self, document):
        super().__init__(self.localdict)
        self.document = document

    def runcode(self, code):
        # stop undo
コード例 #7
0
import kaa
from kaa.filetype.default import modebase
from kaa.theme import Style

MessageBarThemes = {
    'basic': [
        Style('default', 'Base3', 'default'),
        Style('rec', 'Base3', 'red'),
    ],
}


class MessageBarMode(modebase.ModeBase):
    USE_UNDO = False
    message = ''

    def init_themes(self):
        super().init_themes()
        self.themes.append(MessageBarThemes)

    def on_set_document(self, doc):
        super().on_set_document(doc)
        doc.undo = None

    def set_message(self, msg):
        if not msg:
            # Get default message for current document
            if kaa.app.focus and getattr(kaa.app.focus, 'document', None):
                msg = getattr(kaa.app.focus.document.mode,
                              'DEFAULT_STATUS_MSG', None)
            else:
コード例 #8
0
from kaa.filetype.default import keybind
from kaa.command import commandid
from kaa.ui.git import commitdlgmode
from kaa.ui.viewdiff import viewdiffmode
from kaa.ui.msgbox import msgboxmode
from kaa.ui.dialog import dialogmode
from kaa.ui.viewdiff import viewdiffmode

from . import gitrepo

TZ = datetime.timezone(datetime.timedelta(seconds=time.timezone * -1),
                       time.tzname[0])

GitLogTheme = {
    'basic': [
        Style('default', 'White', 'Base01', False, False),
        Style('git-log-header', 'Orange', 'Base02', fillrow=True),

        # todo: right-button with rjust should be defined in another name.
        Style('right-button', 'Base3', 'Base02', rjust=True, nowrap=True),
        Style('right-button.checked',
              'Base3',
              'Orange',
              rjust=True,
              nowrap=True),
        Style('right-button.shortcut',
              'Base3',
              'Base02',
              underline=True,
              rjust=True,
              nowrap=True),
コード例 #9
0
ファイル: markdownmode.py プロジェクト: smorin/kaa
import copy
from kaa.filetype.default import defaultmode
from kaa import doc_re
from kaa.theme import Style
from kaa.command import commandid
from kaa.command import norec
from kaa.command import norerun
from kaa.keyboard import *
from kaa.syntax_highlight import *


MarkdownThemes = {
    'basic': [
        Style('escape', 'default', 'default'),
        Style('header', 'Blue', None),
        Style('hr', 'Green', None),
        Style('strong', 'Magenta', None),
        Style('emphasis', 'Blue', None),
        Style('literal', 'Cyan', None),
        Style('reference', 'Red', None),
        Style('role', 'Cyan', None),
        Style('substitution', 'Green', None),
    ],
}


class LinkToken(Span):
    # [xxx](yyy "xzzzz")
    # [xxx]:
    # ![xxx]
コード例 #10
0
import unicodedata
import copy
from kaa.filetype.default import defaultmode
from kaa import doc_re
from kaa.theme import Style
from kaa.command import commandid
from kaa.command import norec
from kaa.command import norerun
from kaa.keyboard import *
from kaa.syntax_highlight import *

RstThemes = {
    'basic': [
        Style('header', 'Blue', None),
        Style('block', 'Orange', None),
        Style('directive', 'Green', None),
        Style('table', 'Cyan', None),
        Style('strong', 'Magenta', None),
        Style('emphasis', 'Blue', None),
        Style('literal', 'Cyan', None),
        Style('reference', 'Red', None),
        Style('role', 'Cyan', None),
        Style('substitution', 'Green', None),
    ],
}


def _build_seps():
    starts = []
    ends = []
コード例 #11
0
ファイル: filenameindexmode.py プロジェクト: smorin/kaa
import os
import kaa
from kaa import doc_re
from kaa import document
from kaa.keyboard import *
from kaa.theme import Style
from kaa.filetype.default import defaultmode
from kaa.command import commandid
from kaa.command import norec
from kaa.command import norerun

FilenameIndexThemes = {
    'basic': [
        Style('filenameindex-filename', 'Green', 'Default'),
        Style('filenameindex-lineno', 'Green', 'Default'),
    ],
}

filenameindex_keys = {
    '\r': ('filenameindex.showmatch'),
    '\n': ('filenameindex.showmatch'),
}


def _enc_japanese(filename):
    encoding = kaa.app.storage.guess_japanese_encoding(filename)
    if encoding:
        return encoding
    else:
        kaa.app.messagebar.set_message(
            'Cannot detect text encoding:: {}'.format(filename))
コード例 #12
0
import os
import kaa
from kaa import document
from kaa.theme import Style
from kaa.ui.dialog import dialogmode
from kaa.filetype.default import keybind
from kaa.ui.itemlist import itemlistmode

FileInfoThemes = {
    'basic': [
        Style('button', 'Base3', 'Blue'),
        Style('shortcut',
              'Base3',
              'Orange',
              bold=True,
              underline=True,
              nowrap=True),
    ],
}


class FileInfoMode(dialogmode.DialogMode):
    autoshrink = True

    KEY_BINDS = [
        keybind.cursor_keys,
        keybind.edit_command_keys,
        keybind.emacs_keys,
        keybind.macro_command_keys,
    ]
コード例 #13
0
import re
from kaa.filetype.default import defaultmode
from kaa.theme import Style
from kaa import encodingdef
from kaa.syntax_highlight import *

# todo: highlighter should be written.

CSSThemes = {
    'basic': [
        Style('media-selector', 'yellow', 'default'),
        Style('css-selector', 'magenta', 'default'),
        Style('css-propname', 'cyan', 'default', bold=True),
        Style('css-propvalue', 'green', 'default', bold=True),
    ],
}


class MediaToken(SingleToken):
    def on_start(self, doc, match):
        pos, terminates = yield from super().on_start(doc, match)
        pos = yield from self.tokenizer.MediaCSSTokenizer.run(doc, pos)

        return pos, False


class RuleSetToken(SingleToken):
    def on_start(self, doc, match):
        pos, terminates = yield from super().on_start(doc, match)
        if match.group(0) == '{':
            pos = yield from self.tokenizer.PropTokenizer.run(doc, pos)
コード例 #14
0
        self.update_doc(items)
        if not self.items:
            sel = None
        elif index < len(self.items):
            sel = self.items[index]
        else:
            sel = self.items[-1]

        self.update_sel(wnd, sel)
        self.port.del_breakpoint(bp)
        self.port.display_breakpoints()


DebugThemes = {
    'basic': [
        Style('line', 'Orange', None),
        Style('filename', 'Cyan', None),
        Style('lineno', 'Cyan', None),
        Style('funcname', 'Cyan', None),
        Style('dirname', 'Cyan', None),
        Style('status', 'Base3', 'Red', nowrap=True),
        Overlay('current_stack', 'Black', 'Yellow'),
    ],
}

callstack_keys = {
    down: 'callstack_keys.next',
    (ctrl, 'n'): 'callstack_keys.next',
    (ctrl, 'f'): 'callstack_keys.next',
    tab: 'callstack_keys.next',
    up: 'callstack_keys.prev',
コード例 #15
0
ファイル: diffmode.py プロジェクト: smorin/kaa
from kaa.filetype.default import defaultmode
from kaa.theme import Style
from kaa.syntax_highlight import *

DiffThemes = {
    'basic': [
        Style('default', 'Base00', None),
        Style('fromfile', 'Orange', None),
        Style('tofile', 'Yellow', None),
        Style('hunk', 'Blue', None),
        Style('remove', 'Orange', None, bold=True),
        Style('add', 'Yellow', None, bold=True),
        Style('header', 'Orange', None),
    ],
}


def make_tokenizer():
    return Tokenizer(tokens=[
        ('fromfile', Span('fromfile', r'^---', '$')),
        ('tofile', Span('tofile', r'^\+\+\+', '$')),
        ('hunk', Span('hunk', r'^@@', '@@')),
        ('add', Span('add', r'^\+', '$')),
        ('remove', Span('remove', r'^-', '$')),
        ('header', Span('header', r'^\S+', '$')),
    ])


class DiffMode(defaultmode.DefaultMode):
    MODENAME = 'Diff'
    tokenizer = make_tokenizer()
コード例 #16
0
from pathlib import Path
import kaa
from kaa.keyboard import *
from kaa.theme import Style
from kaa.filetype.default import defaultmode
from kaa import document
from kaa.filetype.default import keybind
from kaa.command import commandid
from kaa.ui.git import commitdlgmode
from kaa.ui.viewdiff import viewdiffmode
from kaa.ui.msgbox import msgboxmode
from . import repo

GitTheme = {
    'basic': [
        Style('git-header', 'Cyan', None),
        Style('git-button', 'Orange', 'Base02'),
        Style('git-untracked', 'Orange', None),
        Style('git-not-staged', 'Red', None),
        Style('git-staged', 'Green', None),
    ],
}

status_keys = {
    tab: 'git.status.next',
    right: 'git.status.next',
    down: 'git.status.next',
    (shift, tab): 'git.status.prev',
    left: 'git.status.prev',
    up: 'git.status.prev',
    ' ': 'git.status.press',
コード例 #17
0
                m = re.search(br'charset=(.*)', value, re.DOTALL)
                if m:
                    return str(m.group(1).strip(), 'utf-8')
                break

    # XHTML: <?xml version="1.0" encoding="UTF-8"?>
    m = re.search(br'<\?xml ', b, re.DOTALL)
    if m:
        for name, value in iter_b_attr(b[m.end():]):
            if name == b'encoding':
                return str(value.strip().strip(), 'utf-8')


HTMLThemes = {
    'basic': [
        Style('html-decl', 'Red', 'default'),
        Style('html-tag', 'Magenta', 'default'),
        Style('html-attrname', 'green', 'default'),
        Style('html-attrvalue', 'yellow', 'default'),
    ],
}

RE_ATTRNAME = doc_re.compile(
    r'>|(?P<ATTRNAME>[-._:a-zA-Z0-9]+)(?P<EQUAL>\s*=)?\s*')
RE_ATTRVALUE = doc_re.compile(r'\s*(?P<ATTRVALUE>({}))'.format('|'.join(
    ['[-._:a-zA-Z0-9]+', '(?P<Q1>"[^"]*")', "(?P<Q2>'[^']*')"])))


def iter_attrs(doc, pos):
    while True:
        m = RE_ATTRNAME.search(doc, pos)
コード例 #18
0
ファイル: dialogmode.py プロジェクト: smorin/kaa
import re
from kaa import cursor, keyboard
from kaa.filetype.default import modebase
from kaa.theme import Style
from kaa.exceptions import KaaError

DialogThemes = {
    'basic': [
        Style('default', 'Base3', 'Base02', False, False),
        Style('caption', 'Orange', 'Base02', nowrap=True),
        Style('blank-line-header', 'Blue', None),
        Style('activemark', 'Base02', 'Yellow', nowrap=True),
        Style('nonactivemark', 'Yellow', 'Base02', nowrap=True),
        Style('button', 'Base3', 'Base01', nowrap=True),
        Style('button.shortcut',
              'Base3',
              'Base01',
              underline=True,
              nowrap=True),

        # todo: right-button with rjust should be defined in another name.
        Style('right-button', 'Base3', 'Base01', rjust=True, nowrap=True),
        Style('right-button.checked',
              'Base3',
              'Orange',
              rjust=True,
              nowrap=True),
        Style('right-button.shortcut',
              'Base3',
              'Base01',
              underline=True,
コード例 #19
0
import copy

from kaa import doc_re
from kaa.command import commandid, norec, norerun
from kaa.filetype.default import defaultmode
from kaa.keyboard import ctrl
from kaa.theme import Style
from kaa.syntax_highlight import *

INIThemes = {
    'basic': [
        Style('section', 'Blue', None, bold=True),
        Style('param-name', 'Orange', None, bold=True),
    ]
}


def ini_tokens():
    return [
        ('comment', Span('comment', r';', '$')),
        ('section', Span('section', r'^\[', r'\]')),
        ('param-name', SingleToken('param-name', [r"^([a-zA-Z0-9_-])+"])),
    ]


def make_tokenizer():
    return Tokenizer(tokens=ini_tokens())


INIMENU = [
    ['&Comment', None, 'code.region.linecomment'],