How do I get input from the console in Red language - rebol

I'm writing a console program (target MSDOS) in Red language and I need to ask the user to enter a character or a string, then to press Enter.
I can't seem to find how to do it, I've read the docs here (http://www.red-by-example.org/index.html) to no avail.
I tried something like this:
read.red
Red [
]
print "Please make your choice then press Enter"
x: input
print x
It works in the "Red Console" with red read.red but when I compile with red -r -t MSDOS read.red I get an error:
Compiling C:\apps\red-read\read.red ...
*** Compilation Error: undefined word input
*** in file: C:\apps\red-read\read.red
*** near: [
input
]
How do I ask for input from a Red console program?
I'm using Red version: --== Red 0.6.3 ==--.

Okay, I did some testing and got it working on my end. You need 2 things.
1) You need the latest build, not 0.63. You can grab the automated build from master from the downloads page.
2) You need a reference in your file to use the console. Here is the updated code which will work on Windows with the latest version.
Red [
]
#include %environment/console/CLI/input.red
print "Please make your choice then press Enter"
x: input
print x
This info was buried away in an article on github. Also, you were right about MSDOS.

Related

replace the kscreenlocker_greet

Sorry my English language
I need the following
If you launch the menu -Start -> Shutdown -> Lock
Then you can see the lock screen
Now press CTRL + ALT +F2
let's log in to this terminal under the root user
And let's see the running processes ps -eH | less
We will see the process tree, and who started whom
You can find the following
ksmserver -> kscreenlocker_greet
If you look at how kscreenlocker_greet was launched using ps -aux | grep greet
Then we will see the following
/usr/libexec/kf5/kscreenlocker_greet --immediateLock --ksldfd
Is it possible somewhere (I hope it's not hard code) to replace this command with another command or an application being launched? And if so, where can it be found? Very necessary!
I would like to replace the command call with another application.

Error in parse(text = x, srcfile = src): <text>:13:6: unexpected symbol 12: 13: This R ^

I am trying to create and run a simple .Rmd (RMarkdown file) on Kaggle.
When I create a new RMarkdown on Kaggle, when I click 'Run All' to run the Rmd code, I see:
Your Kernel is now running in the cloud.
Enter some code at the bottom of this console and press [Enter].
Session is starting...
Session started.
ERROR
Error in parse(text = x, srcfile = src): <text>:13:6: unexpected symbol 12: 13: This R ^
How can I successfully run a sample RMarkdown on Kaggle?
Notes
Similar problem outlined 10 days ago here.
The comment isn't helpful (it's just a shortcut instead of pressing the 'Run All' button)
Problem also seems to be mentioned 2 days ago here
Reproducible example
When creating a new RMarkdown on Kaggle, I do the following.
From the kaggle.com homepage, click on 'Code' on the left hand side, then on 'New Notebook':
When I do this, it is immediately clear that the interpreter doesn't lint the code correctly (look at the colours):
For reference, the language is 'RMarkdown':
And the editor type is 'Script':
And when I click 'Run All':
Click 'Save Version' (top right of screen)
That will run (i.e. 'knit') your RMarkdown code (it may take a moment). A link to the knitted document pop up in the bottom left of screen. It's that easy!

WT: Paste multiple lines to Windows Terminal without executing

In the original PowerShell console it was possible to paste and edit multiline commands before executing it
For example this multiline script:
Write-Host "===== 1 ====="
Write-Host "===== 2 ====="
Write-Host "===== 3 ====="
Write-Host "===== 4 ====="
results in the following output
Unfortunately, in the Windows Terminal pasting of the same script results in a very different output
Any ideas how to "fix" the multiline pasting in the Windows Terminal?
The solution for me was to just comment out a line in the terminal setting.json with { "command": "paste", "keys": "ctrl+v" }
And then it works - here the expected output
Edit:
After uncommenting the Ctrl+V chord in the settings.json, the paste functionality is ensured by the PSReadLine module (see Get-PSReadLineKeyHandler -Chord ctrl+v) but Ctrl+V will stop to work in other shells - use Shift+Ctr+V instead
Also pasting with right click will run each line right away. Also control-v makes it easier to paste unicode characters (at least in cmd/powershell console). Note that control-v gets remapped with psreadline's emacs edit mode option.
I know it is not ideal you can convert linebreaks to semicolons
Write-Host "===== 1 =====";Write-Host "===== 2 =====";Write-Host "===== 3 =====";Write-Host "===== 4 ====="
Online converter here.
Just tick the check box for highlighted setting

oh-my-zsh cursor up before program has finished vs after, how to make them behave consistently

I've noticed that if I press up arrow at a prompt then I get the previous command and up again gets me the command before that.
Whereas if I press up arrow before the previous program has completed then instead I get the previous command displayed, the cursor is at the end of the line, but oh-my-zsh is now in "search for lines that start with ... " mode meaning I can't press up to get the previous command.
I'm sure this behavior is well known and expected but just in case you don't get it you can repo it like this
Type ls return
Type sleep 3 return
wait 3 seconds for prompt to appear
press ⬆ (should show sleep 3)
press ⬆ again (should show ls)
press return (to run ls)
Type sleep 3 return ⬆ (press the up arrow before the 3 seconds elapses)
It should now be showing sleep 3
Press ⬆
it will still be showing sleep 3 but it want it to be showing ls. Instead it is in "search for commands that start with sleep 3 mode instead of just go to previous command mode.
To make try to clear in both cases these are the steps
lsreturn
sleep 3return
⬆
⬆
But they end up with different results depending on if step3 happens before or after step2 finishes.
Note I saw this Q&A: https://unix.stackexchange.com/questions/324623/how-to-make-oh-my-zsh-history-behavior-similar-to-bashs
But that doesn't seem to be what I'm looking for. I like oh-my-zsh's partial line + up = search for lines that start with the partial. What I'm trying to fix is that if I press up on step 2 above it magically inserts a partial where as if I wait until step 2 finishes it doesn't.
How do I get oh-my-zsh to be consistent here so that a premature up arrow behaves the same as a normal up arrow?
I'm surprised this question isn't common. It's seriously infuriating to have the terminal act inconsistently. I'd except most devs using oh-my-zsh to run into this issue all the time and be massively frustrated.
The example above with sleep 3 is only to make it easy to show the problem. In actual usage the problem happens frequently even with short lived commands. I type say git status return git commit somefile -m "short comment" return ⬆⬆ expecting to see "git status". 66% of the time I get git status and the other 34% I get `git commit somefile -m "short comment" and pressing ⬆ again just blinks the cursor and I have to press Ctrl-C to break out of zsh's partial complete mode.
The fact that this does not seem to be a common complaint for oh-my-zsh makes me wonder if I have something setup wrong.
To make it clearer run zsh without oh-my-zsh.
zsh -d -f
autoload -U up-line-or-beginning-search
zle -N up-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search
Now try the steps above. You'll get consistent behavior.
This might be an overkill solution but, following this guide you can see that you can bind new actions to the up/down arrow key. So if you add:
bindkey "^[[A" up-line-or-beginning-search # Up
bindkey "^[[B" down-line-or-beginning-search # Down
to your ~/.zshrc, it should remove the functionality you talked about. I managed to get it to work while still maintaining regular search capabilities but this is not thoroughly tested and should probably be used with care.

Colored output in Runnig console in IDEA (PyCharm)

I try log colored messages to PyCharm running console.
Yes, I have read that running console and embedded terminal is different thing, but:
For my code emited log message printed white, but it look colored if I just print() message. So looks like running console support colors, but I don't understand how enable it.
class DefaultHandler(logging.Handler):
def emit(self, record):
log_entry = self.format(record)
m = re.match('^(\[.*?\])', log_entry)
if m:
time = click.style(m.groups()[0], fg='magenta')
msg = click.style(log_entry[m.end():], **get_log_format(record))
click.echo(time + msg) # <- log emit
print(time, msg) # <- just print
else:
click.secho(log_entry, **get_log_format(record))
As you can see log message is white, but printed message is colored.
I'm not positive what your question is, but PyCharm has support for different colors on the console.
Console: Background, Error, output, Standard output, System output, User input
Log Console: Error, Expired entry, Warning
ANSI Colors
You have the ability to look at the defaults and modify them through Settings | Editor | Color Scheme | Console Colors. Is this what you're looking for?