Git Product home page Git Product logo

babi's People

Contributors

7brokenmirrors avatar asottile avatar brynphillips avatar clasherkasten avatar danielchabrowski avatar jkittner avatar keisukefd avatar mmillican avatar pganssle avatar pre-commit-ci[bot] avatar rmorshea avatar villelaitila avatar vrumger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

babi's Issues

Improve comment handling

initial support for :comment was added in #85 -- however this isn't quite correct

for instance these cases I feel are wrong:

case 1

input

  file { '/home/ubuntu/.config':
    ensure => 'directory',
    owner  => 'ubuntu',
    group  => 'ubuntu',
  } ->

output

  # file { '/home/ubuntu/.config':
    # ensure => 'directory',
    # owner  => 'ubuntu',
    # group  => 'ubuntu',
  # } ->

case 2

input

  #file { '/home/ubuntu/.config':
  #  ensure => 'directory',
  #  owner  => 'ubuntu',
  #  group  => 'ubuntu',
  #} ->

output

  file { '/home/ubuntu/.config':
  ensure => 'directory',
  owner  => 'ubuntu',
  group  => 'ubuntu',
  } ->

it says no module named "cson"

~/Desktop/babi $ ./bin/download-theme vs-dark-asottile https://gist.github.com/asottile/b465856c82b1aaa4ba8c7c6314a72e13/raw/22d602fb355fb12b04f176a733941ba5713bc36c/vs_dark_asottile.json
Traceback (most recent call last):
  File "./bin/download-theme", line 11, in <module>
    import cson  # pip install cson
ModuleNotFoundError: No module named 'cson'

babi: error: unrecognized arguments: version

Examples

$ babi --version
babi: error: unrecognized arguments: --version

Current Output

babi: error: unrecognized arguments: --version

Expected Output

0.0.420

System Information

{
  "compiled": "2020-04-04T03:24:50",
  "NimVersion": "1.2.0",
  "hostCPU": "amd64",
  "hostOS": "linux",
  "cpuEndian": "littleEndian",
  "getTempDir": "/tmp/",
  "now": "2020-04-04T17:38:29-03:00",
  "getCurrentEncoding": "UTF-8",
  "getFreeMem": 385024,
  "getTotalMem": 528384,
  "getOccupiedMem": 92576,
  "countProcessors": 8,
  "arch": "x86_64",
  "FileSystemCaseSensitive": true,
  "gcc": "gcc (Arch Linux 9.3.0-1) 9.3.0",
  "git": "2.25.1",
  "node": "v13.12.0",
  "python": "3.8.1",
  "ssd": true
}

Proposed Labels

bug, minor, easy

Proposed Assignee

  • asottile

wide characters

paste this in a bunch and things are broken :'(

๐Ÿ™ƒ

implement find / replace history

  • up and down: need to navigate through the history (with a blank at the bottom -- and you can edit others you find above????)
  • pressing enter appends to the history
  • need to save the history (nano uses ~/.local/share/nano/...) -- XDG_DATA_HOME
  • store each individual history separately? (nano does a sneaky thing and stores the find at the top and replace at the bottom)
  • nano writes the history file on close -- is this what we want?
  • ^R match previous history entry

Improve documentation for developers

README:md should give info on how to install required dev dependencies and how to run the unit tests. E.g. installation of tmux is not mentioned anywhere.

Too long filenames cause test failure

Description

This demonstrates failure mode of some tests, where the temporary directory path generated by pytest is too long to fully fit into the header. (encountered on MacOS)

This leads to the assertions on the visible contents to fail. For example: looking for the modified indicator ' *', or exact match on the filename or particular part of it.

Example breaking test

from testing.runner import and_exit

def test_failing_too_long_filename(run, tmpdir):
    path = str(tmpdir.join('file' * 20 + '.txt'))
    assert len(path) > 80
    with run(path) as h, and_exit(h):
        h.press('a')
        h.await_text(' *')

The top of the resulting screen:

===============================================================================
 babi v0.0.7 lefilefilefilefilefilefilefilefilefilefilefilefilefilefilefilefilef
a

Possible solution

The filename should probably be truncated in a consistent manner, without hiding the indicator or other such information.

This is also what nano does:

  GNU nano 2.0.6 File: ...filefilefilefilefilefile.txt Modified

a

Currently failing tests

Running with pytest tests/ -k fake:

=============================================== short test summary info ===============================================
FAILED tests/features/cut_uncut_test.py::test_cut_and_uncut[fake] - AssertionError: expected: ' *'
FAILED tests/features/cut_uncut_test.py::test_selection_cut_uncut[fake] - AssertionError: expected: ' *'
FAILED tests/features/cut_uncut_test.py::test_selection_cut_uncut_backwards_select[fake] - AssertionError: expected:...
FAILED tests/features/cut_uncut_test.py::test_selection_cut_uncut_within_line[fake] - AssertionError: expected: ' *'
FAILED tests/features/multiple_files_test.py::test_multiple_files[fake] - AssertionError: expected: 'file_a'
FAILED tests/features/multiple_files_test.py::test_multiple_files_close_from_beginning[fake] - AssertionError: expec...
FAILED tests/features/multiple_files_test.py::test_multiple_files_close_from_end[fake] - AssertionError: expected: '...
FAILED tests/features/replace_test.py::test_replace_actual_contents[fake] - AssertionError: expected: ' *'
FAILED tests/features/save_test.py::test_mixed_newlines[fake] - AssertionError: expected: 'f *'
FAILED tests/features/save_test.py::test_modify_file_with_windows_newlines[fake] - AssertionError: expected: '*'
FAILED tests/features/save_test.py::test_saving_file_with_multiple_lines_at_end_maintains_those[fake] - AssertionErr...
FAILED tests/features/save_test.py::test_not_a_file[fake] - AssertionError: expected: "d' is not a file"
FAILED tests/features/save_test.py::test_save_on_exit[fake] - AssertionError: expected: 'enter filename: /private/va...
FAILED tests/features/text_editing_test.py::test_backspace_joins_lines[fake] - AssertionError: expected: 'f *'
FAILED tests/features/text_editing_test.py::test_backspace_deletes_text[fake-BSpace] - AssertionError: expected: 'f *'
FAILED tests/features/text_editing_test.py::test_backspace_deletes_text[fake-^H] - AssertionError: expected: 'f *'
FAILED tests/features/text_editing_test.py::test_delete_removes_character_afterwards[fake] - AssertionError: expecte...
FAILED tests/features/text_editing_test.py::test_delete_at_end_of_line[fake] - AssertionError: expected: 'f *'
FAILED tests/features/text_editing_test.py::test_press_enter_beginning_of_file[fake] - AssertionError: expected: 'f *'
FAILED tests/features/undo_redo_test.py::test_undo_redo_mixed_newlines[fake] - AssertionError: expected: ' *'
FAILED tests/features/undo_redo_test.py::test_undo_redo_with_save[fake] - AssertionError: expected: ' *'

Error when adding theme to `~/.config/babi/theme.json`

Hi Anthony,
I was testing babi on my Ubuntu 18.04 server via SSH and it worked perfectly fine until I tried to add themes to ~/.config/babi/theme.json
I tried to add this theme. I simply copy/pasted it into a file named theme.json.
I am using Python 3.6.9 and when executingbabi theme.json the following error comes up:

Traceback (most recent call last):
  File "/home/kittnjdr/.local/bin/babi", line 11, in <module>
    load_entry_point('babi==0.0.1', 'console_scripts', 'babi')()
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/main.py", line 63, in main
    return c_main(stdscr, args)
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/main.py", line 37, in c_main
    screen = Screen(stdscr, args.filenames or [None], perf)
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/screen.py", line 78, in __init__
    Syntax.from_screen(stdscr, color_manager),
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/hl/syntax.py", line 143, in from_screen
    theme = Theme.from_filename(xdg_config('theme.json'))
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 152, in from_filename
    return cls.from_dct(json.loads(contents))
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 139, in from_dct
    return cls(Style(**default), TrieNode.from_dct(root))
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 74, in from_dct
    k: TrieNode.from_dct(v) for k, v in dct['children'].items()
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 74, in <dictcomp>
    k: TrieNode.from_dct(v) for k, v in dct['children'].items()
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 74, in from_dct
    k: TrieNode.from_dct(v) for k, v in dct['children'].items()
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 74, in <dictcomp>
    k: TrieNode.from_dct(v) for k, v in dct['children'].items()
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 76, in from_dct
    return cls(PartialStyle.from_dct(dct), children)
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/theme.py", line 48, in from_dct
    kv['fg'] = Color.parse(dct['foreground'])
  File "/home/kittnjdr/.local/lib/python3.6/site-packages/babi/color.py", line 11, in parse
    return cls(r=int(s[1:3], 16), g=int(s[3:5], 16), b=int(s[5:7], 16))
ValueError: invalid literal for int() with base 16: 'hi'

Maybe this theme is not suitable?

How to activate syntax highlighting

virtualenv -p /usr/bin/python3 venv
source venv/bin/activate
pip install -r dev-requirements.txt
pip install cson

./bin/download-theme vs-dark-asottile https://gist.github.com/asottile/b465856c82b1aaa4ba8c7c6314a72e13/raw/22d602fb355fb12b04f176a733941ba5713bc36c/vs_dark_asottile.json

python setup.py develop
babi test.py

cat ~/.config/babi/theme.json
{"$schema": "vscode://schemas/color-theme", "name": "Dark (Visual Studio)", "colors": {"editor.backgro....

make it async

The ability to asynchronously populate the contents of a buffer from a subprocess, and to update things without blocking, is a key feature of an extensible editor with a good user experience. Otherwise, extensions have a tendency to block the user interface and generally bog down as you add more of them.

Please consider adding support for this. Thanks!

(I dream of one day replacing my reams and reams of emacs lisp with Python, and Babi seems like a promising contender for that ;-))

hang on style tags in html

typing this causes an infinite hang

<!doctype html> 
<html>
<head>
    <style>
    </style

and can only be killed with TERM

race in background / close

sometimes when closing and backgrounding at nearly the same time, it can cause babi to break the terminal

here's an example of what happens in that case:

Use commands for everything with default keymap sets

You've said on stream that you can use Ctrl+X to close, type :q, or use the emacs thing...

What if you stick to creating a set of commands, but create default keymaps for each of those. Like, on setup, ask the user what editor they're most comfy with. If they say nano, add a set of keymaps that are specific to Nano, like ctrl+x, ctrl+o, ctrl+f, etc. If they say emacs, add that keymap set, and if they say vim, leave them to set their own. Obviously within reason.

That'd make it approachable by everyone.

I'd help implement this but it's Python. No.

tab size

is this even available in python? do I need ctypes shenanigans? should I make a PR to cpython to add this api?

Familiar forward deletion keyboard shortcut Ctrl-D

Many developers and shell users are used to forward delete characters with Ctrl-D. In bash and zsh, if there are any character under the cursor, that is deleted with it. Also nano behaves similarly.

So, I argue that it would be consistent (with the rest of the world) to also let users to do forward delete with Ctrl-D, and therefore implement that binding in babi also, as babi is already consistent with nano in so many other ways.

refresh syntax on saving

probably only on these situations:

  1. first line changes
  2. file extension changes (though currently saving to another file is also broken, lol)

some keys not working inside of tmux while running st terminal emulator

The following don't work under tmux with

set -g default-terminal "screen-256color"

in the ~/.tmux.conf

(I heard on your stream that you dislike tmux, still babi should work on tmux)

these do not work:

shift-left, shift-right, shift-up, shift-down, in fact any selection key combination

these also don't work:

alt-left, alt-right, ctrl-left, ctrl-right

these do work:

tab and shift-tab work

colors, highlighting, everything else works. pretty usable.

handling of escape sequences

curses does not recognize all of the key combinations, as such I'll need to handle them manually

I think something like this will work:

        wch = stdscr.get_wch()
        if wch == '\033':
            stdscr.nodelay(True)
            try:
                while True:
                    try:
                        wch += stdscr.get_wch()
                    except curses.error:
                        break
            finally:
                stdscr.nodelay(False)

then I'll need to translate part(s) (?) of this table to work: https://invisible-island.net/xterm/xterm-function-keys.html

this blocks proper ^Home / ^End / ^ArrowKey support

syntax highlighting

gotta make it happen eventually

the hint that chat gave me is to implement it using textmate syntax -- this is apparently what vscode does and makes it easy to get a bunch of existing syntax highlighting working quickly

gotta parse that format though ๐Ÿค” (and then implement the actual tokenization, etc.)

race condition with extended escape sequences pressed too quickly

=================================== FAILURES ===================================
______________ test_ctrl_up_causing_cursor_movement_should_fix_x _______________

tmpdir = local('/tmp/pytest-of-asottile/pytest-14/test_ctrl_up_causing_cursor_mo0')

    def test_ctrl_up_causing_cursor_movement_should_fix_x(tmpdir):
        f = tmpdir.join('f')
        f.write('line_1\n\nline_2\n\nline_3\n\nline_4\n')
    
        with run(str(f), height=5) as h, and_exit(h):
            h.press('^Down')
            h.press('^Down')
            h.press('Down')
            h.press('Down')
            h.press('Right')
>           h.await_text('line_3')

tests/babi_test.py:878: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <tests.babi_test.PrintsErrorRunner object at 0x7f23b685ec50>
text = 'line_3', timeout = None

    def await_text(self, text, timeout=None):
        """copied from the base implementation but doesn't munge newlines"""
        with self._onerror():
            for _ in self.poll_until_timeout(timeout):
                screen = self.screenshot()
                if text in screen:  # pragma: no branch
                    return
            raise AssertionError(
>               f'Timeout while waiting for text {text!r} to appear',
            )
E           AssertionError: Timeout while waiting for text 'line_3' to appear

tests/babi_test.py:240: AssertionError
----------------------------- Captured stdout call -----------------------------
===============================================================================





===============================================================================
 babi v0 p/pytest-of-asottile/pytest-14/test_ctrl_up_causing_cursor_mo0/f
line_1

line_2

===============================================================================
 babi v0 p/pytest-of-asottile/pytest-14/test_ctrl_up_causing_cursor_mo0/f
line_1

line_2
     unknown key: Key(wch='\x1b[1;5B\x1b[1;5B', key=-1, keyname=b'unknown')
===============================================================================
===============================================================================





===============================================================================
 babi v0 p/pytest-of-asottile/pytest-14/test_ctrl_up_causing_cursor_mo0/f
line_1

line_2

===============================================================================
 babi v0 p/pytest-of-asottile/pytest-14/test_ctrl_up_causing_cursor_mo0/f
line_1

line_2
     unknown key: Key(wch='\x1b[1;5B\x1b[1;5B', key=-1, keyname=b'unknown')
===============================================================================

this can be reproduced with the testsuite fortunately

probably need some amount of ungetwch to make this work properly -- can probably terminate early if seeing another escape character '\x1b

suspend tests fail on wsl arch tmux 2.9a

Whether it's because you're using old Tmux (a la #7) or not, I don't know.

Being on Arch, I get the latest versions of tmux, and that means I seem to get Babi errors early lol.

The error is caused in test_suspend. It's an AssertError waiting for 'babi v0' to show up.

Weird characters after saving and reopening files.

print("hello` world"!) #hello world!^M

^M

^M

def now(words):^M

    print(words)^M

^M

def("hell yeah!")^M

^M

^M

^M

Seems that while using babi on Windows when opening and saving, then reopening the file I create a bunch of ^M. I can recreate both ways to exit, via :q and ctrl + x.

regex replace invalid replace causes crash

$ nano babi/file.py 
Traceback (most recent call last):
  File "/home/asottile/bin/nano", line 8, in <module>
    sys.exit(main())
  File "/home/asottile/opt/venv/lib/python3.6/site-packages/babi/main.py", line 108, in main
    return c_main(stdscr, args, stdin)
  File "/home/asottile/opt/venv/lib/python3.6/site-packages/babi/main.py", line 50, in c_main
    res = _edit(screen, stdin)
  File "/home/asottile/opt/venv/lib/python3.6/site-packages/babi/main.py", line 30, in _edit
    ret = Screen.DISPATCH[key.keyname](screen)
  File "/home/asottile/opt/venv/lib/python3.6/site-packages/babi/screen.py", line 383, in replace
    self.file.replace(self, search_response, response)
  File "/home/asottile/opt/venv/lib/python3.6/site-packages/babi/file.py", line 142, in clear_selection_inner
    ret = func(self, *args, **kwargs)
  File "/home/asottile/opt/venv/lib/python3.6/site-packages/babi/file.py", line 465, in replace
    replaced = match.expand(replace)
  File "/home/asottile/opt/venv/lib/python3.6/re.py", line 321, in _expand
    template = sre_parse.parse_template(template, pattern)
  File "/home/asottile/opt/venv/lib/python3.6/sre_parse.py", line 895, in parse_template
    this = sget()
  File "/home/asottile/opt/venv/lib/python3.6/sre_parse.py", line 255, in get
    self.__next()
  File "/home/asottile/opt/venv/lib/python3.6/sre_parse.py", line 245, in __next
    self.string, len(self.string) - 1) from None
sre_constants.error: bad escape (end of pattern) at position 24

for example, try a replace with a trailing backslash

pressing tab should indent code

currently this is an unknown key

need to figure out how to manage expanded tabs vs real tabs and how to render the tab size (#4)

Might also want to implement some sort of keystroke to type hard tabs even if they're usually spaces (like nano's Alt-V + Tab)

figure out what's up with ruby

ruby's repository is in a weird spot -- not sure if this is intentional or a bug!?

maybe this is a problem with my textmate implementation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.