Closed synrg closed 3 years ago
My idea for this is to add a button (or potentially a keybind) that copies the lowest visible line in the output of the console. With the changes I made to allow individual lines of scrolling, you should be able to "select" which line you want to copy rather easily just by scrolling the terminal to the line you want to copy.
I'll have to look into this further to see how easy (or not) it would be but it'd probably use the library pyperclip for copying to the clipboard since its already platform-independent.
Alright, this does seem to be something we can do easily over SSH which I assume 99% of mark2 users will be in that category.
In order to do it there are two options:
For starters, the server also needs additional software installed, in the case of pyperclip
it also requires xclip
on Linux but should be fine out of the box for MacOS. Once that was completed:
OR
Overall I'd say it's doable*
* provided the user is competent enough to set it up
An alternative solution (dunno if it's even really a solution) would be to dump the line to a text file the user can open and use traditional text selection to copy and paste through SSH
The code to copy the clipboard is really simple provided the client can actually accept the clipboard data.
The following code would go in here where meta c
= alt + c
since ctrl + c
exits the console
elif key == 'meta c':
text_widget, _ = self.g_output_list.get_focus()
try:
pyperclip.copy(text_widget.get_text())
except pyperclip.PyperclipException:
pass
Alright, this doesn't seem to be something we can do easily over SSH which I assume 99% of mark2 users will be in that category.
agreed. (though did you mean "does", since you are discussing options that use SSH below?)
In order to do it there are two options:
For starters, the server also needs additional software installed, in the case of
pyperclip
it also requiresxclip
on Linux but should be fine out of the box for MacOS. Once that was completed:
Sure. this is not a huge hurdle.
- The server would need to open a connection to the client either over SSH or a socket server and send the data where the client would copy it to the clipboard -> This is insecure or hard to configure
OR
- The client would need to be configured for X11 Forwarding with a suitable server running (X Ming on windows, UNIX should have it natively)
Doesn't sound bad. e.g. I'm using VcXsrv on Win10 (a better XMing), and KiTTY (a better PuTTY) with X11 forwarding, and also openssh on Linux with X11 forwarding.
My typical setup:
So everything is already hooked up this way, and I feel typical mark2 users may not be too unsavvy to set it up if they aren't already set up.
I'm not sure if the "copy to text file" is any better than just opening a new tmux window and grepping the relevant lines out of the relevant log. Getting the relevant lines back into the paste buffer of the controlling desktop session without much fuss is the goal. Example use case:
another use case:
agreed. (though did you mean "does", since you are discussing options that use SSH below?)
Yeah I was typing it while investigating and I meant to say does.
Doesn't sound bad. e.g. I'm using VcXsrv on Win10 (a better XMing), and KiTTY (a better PuTTY) with X11 forwarding, and also openssh on Linux with X11 forwarding.
Yeah I'm planning on setting up the requirements for testing today and will be attempting to get it working.
So everything is already hooked up this way, and I feel typical mark2 users may not be too unsavvy to set it up if they aren't already set up.
With the ease of setup of modern minecraft servers, I wouldn't be surprised if some of the users of mark2 have never used SSH before. I'm in a lot of discord servers for minecraft and a LOT of younger people ask simple questions ("why doesn't my server start?" when its printed clearly on the screen they need to accept the eula and is waiting for their prompt). I will document the install process for windows, but I imagine I might need to document basic setup for linux too (although most modern distros have forwarding on by default)
Wow. Setting up VcXsvr was really simple. Basically just ran the installer and made sure putty was configured to forward and it worked right away with xclip
Alright pyperclip
is having a hard time realizing xclip
exists, might have to just add some code to check for macos and use pbcopy
or xclip
if its some form of linux
EDIT: Might actually be a bonehead move on my part. Stopped handling that exception and got a new error :D lol
Hmm this behaviour seems a bit buggy. I've noticed that the focus
for urwid isn't always on the bottom of the listbox. Will need to see if there is a way to "highlight" the focused line
After WAY too much debugging I think I have it working properly. The selected line is highlighted the same way the selected server is and the highlighting is updated whenever the user scrolls the output of the console using the navigations keybinds.
The copy keybind is Alt + C
since Ctrl + Shift + C
wasn't passed to mark2 in my testing...
See: https://github.com/gsand/mark2/commit/c904422453d34a8030195924abf5cff020f39b68
Leaving this open till I can test more and ensure it doesn't cause major issues
For example, the current highlighting code will also reset the formatting of any color-coded console lines after being selected and unselected... Was messing with restoring formatting and was unsucessful. Will have to test more later.
Example: These warnings should be yellow (ignore the bad formatting of the warning lol... mohist)
Sweet! I haven't time yet to check it out, but want to try it soon.
Found a bug today after adding the highlight, sometimes the output would be bytes and would cause pyperclip to not copy it
In theory, the old attributes from the colored text is here: https://github.com/gsand/mark2/blob/54a6e7ac26104450b19c9e6c8ac66326e86cfde9/mk2/user_client.py#L332 But in my testing, this always had invalid attributes in it, random integers I think that are color data. For example, I saw the number 37 in there that URWID didn't like in the text call and no matter what I did, I couldn't convert the old attributes to valid data to apply to the highlighted old text here where that empty string is https://github.com/gsand/mark2/blob/f7907665183ceacc5b9cff192c5860d217d0bcf5/mk2/user_client.py#L334
Ahh, the integer attributes returned I believe are their "run length"
Managed to get it to restore the attributes with some parsing and string slicing. These would have been white before since I scrolled past them
See changes here: https://github.com/gsand/mark2/commit/0cffb9f81633591a7c8edcf70eab7cb60175fc7e
@synrg Have you had the chance to try out the changes?
My community has been tied up all weekend (myself included) in a non-Minecraft-related event, so no, I have not yet. I plan to check it out later this week.
I upgraded mark2 and tried it out just now.
The upgrade instructions were clear, and since I already have the X server & forwarding set up, the test using xclip at the commandline just worked.
Then mark2 started as usual, and I determined that I alt-uparrow / alt-downarrow to change which line is selected, and alt-c to copy a line. So that all works perfectly.
I guess the only other thing I'd like to see is some sort of way to select multiple lines at once.
Looks good! Thanks.
I guess the only other thing I'd like to see is some sort of way to select multiple lines at once.
This is a limitation of URWID, I couldn't really do it how you'd like. It'd need to be a separate keybinding to add the text to the clipboard rather than replace its contents so you could just keep adding lines to the clipboard
Sure, that would work.
Append text to clipboard added in https://github.com/gsand/mark2/commit/10e901b725488e82343b26dfc90729bca1d5f345. Default keybinding is Alt + X
since modifiers like shift don't wanna work with urwid's keybinding system.
2021-08-04 12:07:15 | [AsyncWorldEdit] Undo cleanup started...
2021-08-04 12:07:15 | [AsyncWorldEdit] ...undo cleanup done.
Clearing the clipboard will need to be handled by the user, mark2 will not clear a user's clipboard. Sometimes there might be a newline at the start of the copied text (even though it checks for an empty clipboard and doesn't put a newline if it is). if that happens just clear the clipboard (Win + V
and then clear all from that new window) and then copy the first line with the normal copy keybinding and then append text to it with the new one.
Think all should be good now, let me know if you experience any bugs with this, but going to close it now as I would consider this feature implemented 😄
actually a good way to do it is alt-arrow-keys to the line to start, alt-c to replace the clipboard with the first line, then alternate between alt-down-arrow and alt-x to add more lines to the clipboard. tried it on the latest & works fine. thanks!
actually a good way to do it is alt-arrow-keys to the line to start, alt-c to replace the clipboard with the first line, then alternate between alt-down-arrow and alt-x to add more lines to the clipboard. tried it on the latest & works fine. thanks!
The original draft of my reply mentioned this but I guess I forgot to re-add it when I rewrote the reply lol
In #125 I mentioned my difficulty trying to copy lines from the mark2 console because it messes with focus. This is a request that you provide a way to copy lines without messing up focus (and preferably without also copying any decorations from window frames).