What methods are there to move the cursor in a command line app?
I've tried simpler things, such as using "\b", but that didn't work:
print("test\ba");
I expected the output tesa but I get testa (\b was ignored).
Update
Regarding (2), that was the output in the webstorm IDE, however it worked fine in the normal OS X Terminal.
On Linux or OSX you can use ANSI sequences https://en.wikipedia.org/wiki/ANSI_escape_code. On Windows you are pretty much out of luck AFAIK. Take a look at https://pub.dartlang.org/packages/ansicolor for an example how to use ANSI codes.
See also this similar question Clearing the terminal screen in a command-line Dart app
Related
I want a vim-like text editor to send code to REPLs including iPython in Windows. In Linux SLIMUX is perfect. (I use WSL often, but sometimes it's inconvenient.)
Let's start with ATOM's platformio-ide-terminal package. Here's the code I send:
and here's what get's sent to the iPython REPL running in Powershell:
For ordinary Python it does not do that; it works fine.
Let's go to NeoVim's iron.nvim, where things are even worse for iPython when sending a selection (<Plug>(iron-send-motion)):
In addition to adding extra characters, the iron.nvim send-selection command fails to even execute the command (an issue logged on Github). The just sits in the REPL until you switch vim windows, go into insert mode, and press enter. While it will not add extra characters to ordinary Python, it will still not execute it (this could be a separate issue).
What's going on with iPython and these extra characters? Is there any way to fix it? Why, on Windows, is it so difficult to send code from a text editor to an arbitrary REPL?
This post on the emacs stack exchange at least has a partial answer: At Version 5, iPython got a "new terminal interface" that was incompatible with Emacs' inferior shells. It makes sense that it would give Atom's and iron.nvim's a hard time as well.
For Atom, starting the shell with ipython --simple-prompt completely solves the problem. For iron.nvim, it at least gets rid of the bad characters. In iron.nvim, I've traded bad characters for the iPython multiline paste loosing its newlines, but that seems out of scope for this question.
I would like to find out which version of Electron an Electron desktop app like Signal Desktop or Visual Studio Code is using. Is there a simple way - like entering a command in the Development Console?
Thanks! Johannes
(Why? I would like to see if it is affected by bugs like https://www.trustwave.com/Resources/SpiderLabs-Blog/CVE-2018-1000136---Electron-nodeIntegration-Bypass/)
You can, if the App enabled developer tools and enabled nodeIntegration. take VS Code as an example:
open the Developer Tools, in the console tab, type
process.versions.electron
documentation here: https://electronjs.org/docs/api/process
or try parsing version from userAgent string
navigator.userAgent.match(/Electron\/([\d\.]+\d+)/)[1]
Open the Developer tools and in the Console tab type:
navigator.userAgent
For example in the Discord app I'm getting:
Mozilla/5.0 ... Electron/9.3.5 ...
Under a Unix-like or Linux system (and possibly under Windows using Cygwin or MSYS shells or WSL, but this is untested there), you can use the strings program even for progams that are built without the developer tools enabled.
Basically, you're just searching for a user-agent string in the binary itself.
Currently, I have been able to do the following:
$ strings example-electron-app-binary-file | grep '^Chrome/[0-9.]* Electron/[0-9]'
Chrome/98.0.4758.141 Electron/17.4.7
That regular expression searches for strings starting with Chrome/, followed by any number of numerical digit and dot characters, a single space, and then Electron/ with any numerical digit after it.
This won't work in all likelihood if your system uses UTF-16 strings, but since browsers tend to use UTF-8 internally there's still a chance it'd work on a Windows electron binary.
Is there a way to just run the matlab (7.9.0) editor and not the rest of the "desktop" on linux?
This can't be done directly, because the editor stopped being a stand-alone executable many releases ago. It is now launched as a separate Java window from the Matlab desktop. However, you could try hiding the desktop once the editor is displayed, using the following simple code snippet:
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.hide % to hide desktop
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.show % to show desktop
Note that if your editor is docked to the desktop, it will be hidden together with the desktop, so be careful...
No, this is no longer possible since r2007a.
You can get Matlab syntax highlighting for emacs and vi, though.
On my windows machine, I can start MATLAB with the -nodesktop option, then once in the command prompt, I start only the editor with edit.
Im not sure if this is different in terms of memory space used, but this way you only get the editor and the command prompt (no auto-completion though)
You can add Matlab syntax highlighting to Kate via a plugin. I don't know about gedit, but there's probably an addon for that as well.
The title is a bit more specific than my actual goal:
I have a command-line program which uses GNU Readline, primarily for command history (i.e. retrieving previous commands using up-arrow) and some other niceties. Right now the program's output appears interspersed with the user's input, which sometimes is OK but the output is asynchronous (it comes via a network connection in response to the input commands), and that gets annoying sometimes (e.g. if lines are output when the user is typing new input).
I'd like to add a feature to this program: a separate "window" for the output. I thought about using ncurses for this. But it appears from the ncurses FAQ that the two libraries are not easy to use together.
I might consider using Editline or tecla instead of Readline, but it's not clear to me if either of those will solve my problem. I'd also consider using something other than ncurses, including a library which provides both kinds of functionality (text-mode windows and command history), but I don't know what might be best.
Oh, and support for colored text might get bonus points. I suspect I may be able to do that with Readline, so maybe it's a separate concern, but if a solution to my problem also makes it easy to add a bit of color to the output, so much the better.
I'm using Ubuntu Hardy (Linux 2.6).
I've now put together a simple example program on GitHub: https://github.com/ulfalizer/readline-and-ncurses.
It supports seamless and efficient terminal resizing and multibyte/combining/wide characters. The code has helpful comments.
Screenshot below:
I have done some searching, and it seems like you are out of luck.
For ncurses alternatives there are SLang, Newt and Turbo
Vision. Slang is much more than just screen handling and thus more
complex, but maybe it can be used for your purpose?. Newt uses the screen
handling and is much simpler, but too simple and single-threaded-mode
for your purpose I think.
Turbo vision is the text mode graphics library from Borland, used by
all their tools in the late 80s/early 90s. Borland released the source
code when the market for that kind of thing diminished, and there is
now a port for linux (side note, this project seems to have written
its own turbo vision implementation). That port is not dead (there have
been some cvs updates this year which compiled fine (the older releases
did not)), but none of the TV examples I found were up to date and I
did only got a few of them to compile before giving up on the rest.
This is a bit of a shame, because TV was a lovely environment to use.
TV is btw C++ (and I assume you are using C?).
For an alternative to readline, there is libkinput, which maybe works
together with ncurses (it says it can use ncurses' terminfo. but I am
not sure if that means that it can co-exists together with ncurses usage)?
Maybe one option is to run readline "externally" to your ncurses program
using rlwrap?
This had me banging my head for a few hours, so just to save people Googling some pain:
If you're using ncurses' builtin SIGWINCH handler with KEY_RESIZE, be aware that readline sets the LINES and COLUMNS environment variables by default. These override any dynamic size calculation (usually with ioctl() TIOCGWINSZ) that ncurses would otherwise do, meaning you'll keep getting the initial terminal size even after resizing the terminal.
This can be prevented by setting rl_change_environment to 0 before initializing readline.
Update:
Here's some additional information I gleaned from the readline sources:
readline's SIGWINCH handling code (which is used if rl_catch_sigwinch is 1) does update LINES and COLUMNS, which seems like it should be sufficient for ncurses. However, when using the alternate readline interface (which makes most sense when combining readline with ncurses), the signal handlers (including the one for SIGWINCH) will only be installed for the duration of each rl_callback_read_char() call, meaning any terminal resize between two calls to rl_callback_read_char() will not be seen by readline.
So it turns out that gdb uses both readline and ncurses. If you're interested in doing this, I recommend that you check out their implementation: http://sourceware.org/git/?p=gdb.git;a=blob;f=gdb/tui/tui-io.c
I've achieved what you've described in a program of mine:
http://dpc.ucore.info/lab:xmppconsole
The following is the file handling io:
http://github.com/dpc/xmppconsole/blob/master/src/io.c
I'm not sure which version you tried. As of today(2012.09.14) It is very simple, We just need to hook our custom function to following function pointers.
rl_getch_function
rl_redisplay_function
rl_completion_display_matches_hook
I did something reasonable here.
I'm using P4COM to communicate with our perforce server. I have written an little utility to simplify our QA of what files have changed from one release to another. I have been using the P4COM interface from Delphi. So far so good.
I though it might be nice to allow users to view the diff between the two versions of the file from within my little utility rather than going back to p4v. So I print (get) the files at each revision using p4COM and the following command
print -o "E:\Development\TempProjects\p4Changes\temp\File_dispatch.pas#25" "//depot/mydepotpath/File_dispatch.pas"#25
and
print -o "E:\Development\TempProjects\p4Changes\temp\File_dispatch.pas#26" "//depot/mydepotpath/File_dispatch.pas"#26
However when I do this from my app using P4COM I seem to get random files (and they appear to be deleted ones). If I run the exact same command from the command line I get perfect results. Running both of these does return a file and correctly dumps it to disk where I want it, its just not the file I've asked for.
Any ideas?
Could it be a backslash issue in the command string? This would work fine at the command line, but a single backslash may be being interpreted as an escape code by whatever language compiler you are using (if C or C++, then this will definitely cause a problem, and that maybe happening under the hood on the P4COM side).
Try using double backslashes and see if that fixes it.
You're probably better of asking this to Perforce support itself, as this sounds like a bug in their software.
As a sidenote : Why do you use p4v? (I hugely prefer p4win myself)