Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding a repl binary #49

Merged
merged 15 commits into from
Nov 15, 2024
Merged

feat: Adding a repl binary #49

merged 15 commits into from
Nov 15, 2024

Conversation

sminez
Copy link
Owner

@sminez sminez commented Nov 13, 2024

This is aiming to be an equivalent to the win command that comes with acme.

ad-repl-2024-11-14_07.53.54.mp4

@rakoo
Copy link

rakoo commented Nov 13, 2024 via email

@sminez sminez changed the title Adding a repl binary feat: Adding a repl binary Nov 14, 2024
@sminez
Copy link
Owner Author

sminez commented Nov 14, 2024

@rakoo getting it to work nicely with sh (including the prompts) is surprisingly difficult in a terminal application. For now I'm hard coding rc and the readme includes instructions on how to install it but I may revisit it in the future. The entire program is 150 lines so its not particularly challenging to hack on or write your own alternatives for 🙂

@davcam
Copy link
Contributor

davcam commented Nov 14, 2024

Wow this is great!
Is there a way of sending "Enter" or Execute via 9p?
If "+win" is buffer 1 say I can 9p to the body i.e.
echo ls | 9p write ad/buffers/1/body
This appends "ls" to the end of the repl window i.e.
$ ls
but doesn't execute it.

@sminez
Copy link
Owner Author

sminez commented Nov 14, 2024

Text appended via the filesystem interface is explicitly not executed as I need to avoid trying to execute output as it gets appended to the buffer. If I added Load and Execute commands that would work I think but you'd need to select the text you are wanting to work with (similar to how the handler for newline at the end of the file in ad_repl is working). So something like this:

echo 'ls' | 9p write ad/buffers/1/body
echo '$-' | 9p write ad/buffers/1/addr
echo 'Execute' | 9p write ad/ctl

edit

The addr being set actually needs to be $-1 not $- for this to work

@sminez
Copy link
Owner Author

sminez commented Nov 14, 2024

@davcam that should work now 👍

@davcam
Copy link
Contributor

davcam commented Nov 14, 2024

@sminez many thanks for this it is close.

When I execute the three lines

echo 'ls' | 9p write ad/buffers/1/body
echo '$-' | 9p write ad/buffers/1/addr
echo 'Execute' | 9p write ad/ctl

I get the below in the +win window with no errors rather than an ls listing

% ls

% 
% 

@sminez
Copy link
Owner Author

sminez commented Nov 14, 2024

Huh...I ran exactly that and it worked for me. Did you have anything else in the buffer at the point you ran this? I ran things immediately after starting ad_repl

@davcam
Copy link
Contributor

davcam commented Nov 14, 2024

whenever I run

echo 'Execute' | 9p write ad/ctl

it outputs

% 
% 

irrespective of the previous lines so perhaps my issue is with "Execute" - could this be due to a difference in interaction with p9p?
My version of plan9port is 20240617-1
I installed ad and ad_repl by

git clone https://github.com/sminez/ad
cd ad 
git checkout repl
cargo install --path ./
cd crates/ad_repl
cargo install --path ./

cargo 1.82.0 (8f40fc59f 2024-08-21)
rustc 1.82.0 (f6e511eec 2024-10-15) (Arch Linux rust 1:1.82.0-2)

@davcam
Copy link
Contributor

davcam commented Nov 14, 2024

Ok I think I understand I was missing a step.
You need to select 'ls' in the +win window to add it to dot right?
Then

echo 'Execute' | 9p write ad/ctl

works for me.
Wait no

echo '$-' | 9p write ad/buffers/1/addr

should do that.

@davcam
Copy link
Contributor

davcam commented Nov 14, 2024

Ok I think the issue is that it is skipping to the next line after

echo 'ls' | 9p write ad/buffers/1/body
9p read ad/buffers/1/addr

2:1
This should be line 1 not line 2
So when I set dot

echo '$-' | 9p write ad/buffers/1/addr
9p read ad/buffers/1/addr

I get
2:1,2:1
which is the line below the 'ls'

@sminez
Copy link
Owner Author

sminez commented Nov 14, 2024

Oh! Sorry 🤦 This is what I'm doing:

ad-repl-test-2024-11-14_14.56.41.mp4

I messed up the command I gave you: the addr you want to set is $-1 not $-

@davcam
Copy link
Contributor

davcam commented Nov 14, 2024

Thanks yes or

echo -n 'ls' | 9p write ad/buffers/1/body
echo '$-' | 9p write ad/buffers/1/addr
echo 'Execute' | 9p write ad/ctl

also works

@davcam
Copy link
Contributor

davcam commented Nov 14, 2024

Is there any way to change the "current" buffer externally?

I tried writing to it

echo 2 | 9p write ad/buffers/current

but got a permission problem

The idea is to have two ad windows open: the LH one is my code where I select lines to change dot

I then run the mysend script below to send to the RH +win for execution

#!/bin/sh

source "$HOME/.ad/lib/ad.sh"

requireAd

varin=$(bufRead 1 dot)
nlines=$(echo "$varin" | wc -l)
echo "$varin" | bufWrite "$bufid" body
echo '$-'"$nlines" | bufWrite "$bufid" addr
echo '$-'"$nlines"',+'$((nlines-1)) | bufWrite "$bufid" addr
echo 'Execute' | 9p write ad/ctl

At the moment I'm having to click in the RH window so that Execute sends to +win
It would be great to be able to modify the current window in the script to save me from moving away from the LH code window.

@sminez
Copy link
Owner Author

sminez commented Nov 14, 2024

@davcam you can use the buffer command along with the id (See Running Built In Commands in :help for details of the available builtins)

For other questions like this would you mind raising an issue rather than asking on this PR? I'd prefer to keep the discussion here related to the PR itself 🙂

@sminez sminez merged commit 4e239cd into develop Nov 15, 2024
7 checks passed
@sminez sminez deleted the repl branch November 15, 2024 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants