a tiny terminal emulator-ish script for norns
tiny-term on GitHubidea: os.execute(‘command’) -> print(“output”) - using io.popen instead for this.
io.popen
is a function in Lua’s standard I/O library
that opens a process by creating a pipe, forking, and invoking the
shell. It can be used to run a shell command and capture its
output.local handle = io.popen("ls")
local result = handle:read("*a")
handle:close()
print(result)local handle = io.popen("ls")
local result = handle:read("*a")
handle:close()
print(result)
the handle is closed with handle:close()
. It’s
important to always close handles when you’re done with them to avoid
resource leaks.
can run most shell commands that don’t require user interaction and don’t rely on specific terminal features.
Here are some examples of commands you should be able to run:
ls
, pwd
, cd
, cp
, mv
, rm
, mkdir
, rmdir
,
etc.cat
, more
, less
, head
, tail
, grep
, sed
, awk
,
etc.date
, uptime
, who
, uname
,
etc.ping
, netstat
, curl
, wget
,
etc.ps
, kill
, top
, etc.
(Note: top
is a terminal-based program, but it can be used
in batch mode, which doesn’t require a terminal. For
example, top -b -n 1
runs top
in batch mode
and exits after one iteration.)Commands that you won’t be able to run include terminal-based
programs that require user interaction or rely on specific terminal
features. Examples of such programs
include vi
, nano
, less
, more
, top
(in
interactive mode), ssh
, tmux
, etc. #
links
- the script opens with a prompt `>` and blinking cursor `_`
- input from keyboard displays after the prompt `> cd home/we/dust_`
- pressing `enter` will execute the command.
- the display will show the executed command and the resulting output
- `pwd -> /home/we/dust/audio`
- the display can be scrolled using k2 or keyboard arrow keys
io.popen
. - while this will prevent the
“TERM environment variable not set” error, it may not be enough to make
all terminal-based programs work correctly. These programs are designed
to be run in a full terminal environment, and io.popen
does
not provide such an environment. They may still fail or behave
unexpectedly, even with the TERM variable set.
luaposix
, which
includes a posix.system
function that can be used to run
shell commands in a full terminal environment.