asottile / babi Goto Github PK
View Code? Open in Web Editor NEWa text editor
License: MIT License
a text editor
License: MIT License
initial support for :comment
was added in #85 -- however this isn't quite correct
for instance these cases I feel are wrong:
file { '/home/ubuntu/.config':
ensure => 'directory',
owner => 'ubuntu',
group => 'ubuntu',
} ->
# file { '/home/ubuntu/.config':
# ensure => 'directory',
# owner => 'ubuntu',
# group => 'ubuntu',
# } ->
#file { '/home/ubuntu/.config':
# ensure => 'directory',
# owner => 'ubuntu',
# group => 'ubuntu',
#} ->
file { '/home/ubuntu/.config':
ensure => 'directory',
owner => 'ubuntu',
group => 'ubuntu',
} ->
~/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'
choices:
reproduction:
babi
hello
^\
hello
and press entery
$ babi --version
babi: error: unrecognized arguments: --version
babi: error: unrecognized arguments: --version
0.0.420
{
"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
}
bug, minor, easy
probably doesn't make too much sense there
https://github.com/asottile/babi#setting-up-syntax-highlighting
$ ./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
ModuleNotFoundError: No module named 'cson'
$
MonkaS
paste this in a bunch and things are broken :'(
๐
~/.local/share/nano/...
) -- XDG_DATA_HOMEfor instance, select this and :comment
1
2
vim and nano can do this, so babi probably should as well
currently off due to pypy/pypy#3064
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.
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.
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
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
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: ' *'
It would be good to explain why you would choose babi
over nano
since the comparison is pretty easy to make given the name and interface.
right now it can keep old statuses which might not be ideal
Open t.sh
Paste this:
set -euxo pipefail
! (python3 -m pyflakes t.py || true) | grep ._array_like.ArrayLike
Put a paren before the first (
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?
this is due to the special case at the end of the file not being handled properly -- thanks for finding this @brynphillips!
Colors doesnt look right, thats the theme i used https://raw.githubusercontent.com/Binaryify/OneDark-Pro/master/themes/OneDark-Pro.json.
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....
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 ;-))
This is used (for example) by dch -v
which currently tries to open a file named +3
-- oops
For example:
babi setup.cfg
^O
2
for example, do a replace with ^
=>
and replace all and the end of the file will be forever broken-ish
typing this causes an infinite hang
<!doctype html>
<html>
<head>
<style>
</style
and can only be killed with TERM
especially on windows, this can result in mojibake
ensure that the open
calls go through encoding='UTF-8'
-- maybe also validate stdin does the same
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.
is this even available in python? do I need ctypes shenanigans? should I make a PR to cpython to add this api?
I just noticed it. Is there a need for the comment here? https://github.com/asottile/babi/blob/master/babi.py#L474
apparently get_wch
(which is supposed to block for input for forever) just kinda doesn't?
reported by @brynphillips
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.
probably only on these situations:
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.
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
here is a statically compiled binary
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.)
=================================== 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
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.
apparently that's a thing: jeff-hykin/better-cpp-syntax#522 (comment)
make sure to verify with vs code first
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.
$ 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
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)
how to make this render properly?
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?
echo -en 'foo\n\n' > t
babi t
babi t
(reopen the file)this used to work, hmmm
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.