Clojure CLI clear screen - clojure

Pardon me but I've just started learning clojure. I've run many commands in REPL CLI. But now I'm not able to clear the CLI screen. cls command also doesn't work inside the REPL. Thanks in advance!

Try pressing Control-l (lower case 'L' - not the number one). If the that doesn't work try starting the REPL using rlwrap, which may implement the readline support for clearing the screen. But this all depends on how you are starting the repl, and on what platform. There's no global way to clear a terminal across Windows and UNIX variants and other containers such as Emacs buffers and Atom/ProtoREPL. This isn't really something the REPL can reasonably support since the buffer is not held by the Clojure/JVM process, but by the container you're using to display it to your screen. It's also likely that your terminal emulator provides a way to clear the buffer.

Related

Is there a way to store and retrieve the history of shadow-cljs' REPL over different sessions? How to use commands used in previous sessions?

I am using Emacs, CIDER, and shadow-clj/shadow-cljs to develop a project
in Clojure/ClojureScript. All this in a macOS Monterey 12.5.
Before that, I was used to programming with Emacs, Slime, Common Lisp, and SBCL.
Sometimes, I want to have a similar UX in this new lisp environment similar to my
previous experience on the other lisp land.
I am having multiple hassles (as expected) and pains with the new environment.
One thing, in particular, has been quite annoying.
After executing cider-jack-in-cljs, shadow-cljs, shadow (REPL),
and app (for the build), the REPL does not "remember" the
previous session. I can't access the commands that I executed before quitting. It only remembers the commands executed on the current session. This is hindering my interactive programming productivity.
In Slime, this was possible! And quite handy.
Moreover, after executing describe-mode in Emacs, I have:
Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption
Column-Number Counsel-Projectile Delete-Selection Display-Line-Numbers
Doom-Modeline Eldoc Electric-Indent File-Name-Shadow Font-Lock
Global-Auto-Revert Global-Display-Line-Numbers Global-Eldoc
Global-Font-Lock Ivy-Prescient Ivy-Rich Line-Number Override-Global
Paredit Projectile Rainbow-Delimiters Recentf Save-Place Savehist
Shell-Dirtrack Show-Paren Transient-Mark Which-Key Wrap-Region
Wrap-Region-Global
(Information about these minor modes follows the major mode info.)
REPL[cljs] mode defined in ‘cider-repl.el’:
Major mode for Clojure REPL interactions.
Inside Cider Major mode, I have the command bellow fully working:
C-c M-p cider-repl-history
But, it works only for current session.
In addition, an user suggested that maybe cider-repl-history-mode was not enabled. Indeed, it seems that it has not been enabled - since I can't see it.
If I try to execute the command cider-repl-history-mode a weird thing happens ParEdit appears indicating a problem in parenthesis and the mini buffer echoes:
paredit-mode: Unmatched bracket or quote
This is really weird because although ParEdit is related to Clojure, it seems unrelated to Cider for the case in hand.
Is there some way to preserve CIDER's REPL's history over sessions?
Use cider-repl-backward-input and cider-repl-forward-input to go forward and backward in command history over sessions.
See CIDER // docs - REPL history browser.

Linux keyboard scancode issues: For example, UP ARROW gives ^[[A

We've been struggling for a while now to understand the keyboard scancode behavior in Linux.
When we open a normal bash shell, the arrow keys works as expected: UP shows the previous item in the history etc. However when you spawn a process, arrows does not work as expected anymore. For example, UP prints ^[[A instead of the previous command.
To demonstrate this, do something like:
bash$ ping www.google.com
Now, press UP or DOWN etc. and you will see the wrongly mapped key codes while the process is running. However, when you terminate the process the arrow keys will work again.
We've tested it on CentOs, Ubuntu, Mac and even in different shells (bash, sh, zsh) and the same happens everywhere. I've also tried different keyboard modes using kbd_mode where we tested with RAW and XLATE modes.
The closest thing I could see while searching for answers were IPython users have experienced the same behavior when IPython was not build against readline. However, this is not related to our case as far as I can see.
We are developing a C++ Tcl based console application which uses cin and cout to communicate with, and get input from the user. We are having issues with the arrow keys when we try to access the history of previously entered commands. This is a major issue for us as 99% of people expects the arrow characters to just work.
Any ideas on how we could overcome this would be much appreciated.
You must set the terminal into raw mode to get the scan codes and handle them (that is: disable ICANON, you want the non-canonical mode). You probably also want to disable ECHO (so that it doesn't print your input on the terminal).
That is what readline or linenoise are doing. See here for some code. Esp. see the function linenoiseEnableRawMode. Some other simple sample Python code is here where I have written a simple console media player which checks for the keypresses left ("\x1b[D") and right ("\x1b[C").
The relevant calls are to tcgetattr (to get the current terminal state and modify that state struct to get into raw mode and enable some other useful behavior stuff) and tcsetattr (to set the state).
readline, libedit or linenoise are some libraries which do all that work for you and provide you with history, autocompletion, etc.
At the end, you must restore back the old state, otherwise you get the behavior you are describing in your shell.

cl-opengl under SLIME on MacOS crashing SBCL... bug?

I'd like to do some OpenGL programming in Common Lisp, under Emacs and SLIME. I'm not set on it, but I'm currently trying to use SBCL. If I open up emacs from the start, create a new file with just this one line:
(ql:quickload :cl-opengl)
And then I do M-x slime (and wait for it to load), followed by C-c C-c to compile and run that line, SBCL crashes immediately, every time, prompting a dialog box that says sbcl quit unexpectedly:
I've saved the output that's accessible by clicking the "Report..." button; if that's useful, I can add that here (or put it on pastebin or something)... the short version is it's getting a SIGTRAP.
This happens every time I try to run this under SLIME... but, interestingly, it doesn't happen if I run SBCL from the command-line.
So, the question: Is this a bug in SBCL? In cl-opengl? Something I have mis-configured? Other? Any insights would be greatly appreciated.
Note:
I've done some google searching, and I found a page which provides a workaround of putting the following in ~/.swank.lisp:
(setf swank:*communication-style* :fd-handler)
Indeed, that gets me past the immediate crash, and gets me able to do some work. If that's simply the answer, someone please post it as an answer with an explanation of why that's the thing to do, so that others may find it. Otherwise, I'm imagining this to be a bug, though, that could be fixed, rather than worked around... and/or at least something that I could be helped to better understand; I still don't have a responsive REPL with my current code (basically on brian's brain, as a test case) running (via run), which may or may not be a separate question? Did changing the swank config change that situation for me?
Platform details:
OS: MacOS 10.6.8
SBCL: sbcl#1.1.10_0+fancy from MacPorts; launch header This is SBCL 1.1.10, an implementation of ANSI Common Lisp.
Emacs: macports-installed Emacs Version 24.3 (9.0) (per the GUI about window, or GNU Emacs 24.3.1 (x86_64-apple-darwin10.8.0, NS apple-appkit-1038.36) of 2013-04-07 per M-x version, or the emacs-app#24.3_1 port)
Slime: slime#20130630 from MacPorts
It sounds like a thread support issue with SWANK
The :fd-handler option changes the way SWANK communicates from the default, which is to use separate threads for communication, to using a loop approach (http://www.common-lisp.net/projects/slime/doc/html/Communication-style.html).
There used to be quite a few complaints about using SBCL with threading on Mac OS, these were largely fixed from the look of it; maybe SWANK is having similar issues?
I'm not 100% sure this is the sole cause of your problems, but it's the best explanation I could find.
I have been looking through my setup to see what was different
OS X 10.9
SBCL 1.1.8.0-19cda10
slime-20131003
But the most likely offender is still slime/swank.
I really recommend using quicklisp to manage your slime setup rather than macports, this will keep both slime and swank in sync and up to date. I've been using slime this way for a year or two and have had no issues so far.
From the quicklisp page:
To install and configure SLIME, use:
(ql:quickload "quicklisp-slime-helper")
Then follow the directions it displays. quicklisp-slime-helper will
create a file you can load in Emacs that configures the right
load-path for loading Quicklisp's installation of SLIME
I also made a small video showing how to install emacs+sbcl+quicklisp+slime under windows. The slime part is still relevant on all platforms.
Hope it helps.

Clear console using C++ with Xcode?

I'm trying to make a C++ console application using Xcode 4.1, but I can't find the command for cleaning the screen while the program is executing...
Any ideas? Thanks!
OSX doesn't have "consoles" the way Windows does. It has pseudoterminals, which act like an old-fashioned glass terminal to the program running "inside" them, and like a bidirectional pipe to the program that set them up. That outer program can do whatever it likes with the inner program's input and output. Notable examples of such programs are Terminal.app, which emulates the venerable VT-100, and ssh, which forwards the I/O over a secure channel to its own controlling terminal (which is probably itself a pseudoterminal). This is all by way of saying that there isn't a method that's guaranteed to work, because maybe the program on the outside of the pseudoterminal doesn't have a "screen" that you can meaningfully "clear." (Expect is a good example of a program like that.)
Having said that, though, if there is a screen, these days you can pretty much count on it to respect the VT-100 control codes. So this should do what you want:
std::cout << "\033[2J" << std::flush;
If you find that you need even one more control code, though, it's time to hook your program up to ncurses, which presents a nice friendly API to all the tricks that modern terminal windows are capable of, and will also have your back in the increasingly unlikely event that your program is attached to a terminal (or a program emulating a terminal) that is not a VT-100 nor one of its descendants.

Is there a way to send some procesess with known pid in background?

I am new in Linux and system programming .
I Want to write a c program which finds processes whose cpu% usage are more than a specific given value and sends them to background.
anybody can help me !
I really appreciate it
I'm fairly sure that what you're asking is that you want to detect if a process is using X amount of CPU and if so, take it off the CPU for a while. There's a piece of software already that does this: It's called the kernel. I'm not aware of any way to programatically take another process off CPU unless that other program supports an external interface to reduce its load.
Most likely what you really want to do is configure the nice and other scheduler parameters of the running process so the kernel is more like to to take it off CPU when another program needs to do work.
But what underlying problem are you really trying to solve here? Maybe if you tell us that we can offer an alternate solution.
Please look at source code of process managament utilities like:
htop
top (standard unix command)
ps (standard unix command)
IMHO, You can't.
Background management ensures the shell. So, the & is interpreted for example by /bin/bash command. When pressed CTRL-Z, the kernel stopping your current fg-job, and again by your shell you can send it into background.
Youre looking for the way how to remote control the shell what running some program in fg. I don't know any 'remote-controling' way.
Ofc, here are alternative solutions, for example:
use the screen command, and you can recall the specific screen into your terminal, and can manually send process into bg.
or you can use some screen-sharing utility, to overtake a specific terminal and CTRL-Z, bg
or, you can patch bash and adding remote control functionality. ;)
or, here is something what i don't know. ;) - hm, maybe trap some user-signal handling code in the /etc/profile?
You can read a bit about here: http://en.wikipedia.org/wiki/Process_group
Honestly, after a half hour of thinking I don't get any idea why you want remotely (from the another terminal - by its PID) send some processes from the fg into the bg. Give me no sense.
Can you please tell, what you want achieve?
You probably want to reduce process priority, but I not sure it's good idea.
We send process to background generally to free shell's prompt.
The "+" means that the program "is in the foreground process group". I don't believe, however, that this state at all affects the process's scheduling.
However, you can change it with tcsetpgrp.
From the man page: "The function tcsetpgrp() makes the process group with process group ID pgrp the foreground process group on the terminal associated to fd, which must be the controlling terminal of the calling process, and still be associated with its session. Moreover, pgrp must be a (non-empty) process group belonging to the same session as the calling process."
By my reading, you just call this function and make the shell (or some other program) be the foreground process.