Coding Challenge Project

ccsh

A platform-independent shell written in Java with raw keyboard input, live line editing, command history and a built-in HTTP client over raw sockets.

↗ codingchallenges.fyi
Java 11+ JNA 5.x Raw Sockets ANSI/VT SSL/HTTPS Windows · Linux · macOS

Features

Raw Keyboard Input
Character-by-character reading via JNA (RawConsoleInput), bypassing canonical line-buffering.
Live Line Editing
Cursor movement, insert and delete with full ANSI/VT rendering in-place.
Persistent History
Navigate with ↑ ↓, saved to .ccsh_history and restored on next session.
|
Pipe Support
Chain commands with |. Output of each command feeds the next.
Built-in curl
Full CRUD over raw sockets with SSL, JSON body, custom headers and verbose mode.
Cross-Platform
Windows 10+ (VT + Legacy), Linux, macOS — one codebase, no compromises.

Requirements

Java
11+
JNA
5.x
OS
Win 10+ · Linux · macOS

Build & Run

bash
# Compile
$ javac --module-path <jna-path> -d out src/**/*.java

# Run
$ java -cp out:jna.jar ccsh.Main

# Enter the shell
$ ccsh
ccsh> _

Commands

Shell
ccsh
Start the interactive shell session.
exit
Exit the shell. History is saved automatically.
Filesystem
ls
-a
List files in the current directory. -a includes hidden files.
cd
Change directory. Supports relative and absolute paths.
cd ..
pwd
Print the current working directory.
touch
Create a new empty file in the current directory.
mkdir
Create a new directory. Supports nested paths.
mkdir Parent\Child
Text
cat
-n  -b
Print file contents. Concatenate two files. -n adds line numbers, -b numbers non-empty lines only.
cat file1.txt file2.txt  |  cat -n
wc
Count lines, words, characters and bytes of a file or piped input.
History
history
-clear
Display command history. -clear clears history and deletes .ccsh_history.
Pipe
|
Pipe output of one command into the next. Chain any number of commands.
cd C:\ | ls | wc

curl

Built-in HTTP client over raw sockets. Supports SSL/TLS, custom headers, JSON body and all CRUD methods. Piping is not supported for curl.

Flags
-X <METHOD>
HTTP method: GET POST PUT DELETE
-d <json>
JSON body for POST / PUT requests.
-h <header>
Add a custom request header.
-v
Verbose — prints connection info and prefixes response lines with <.
examples
ccsh> curl -X GET http://jsonplaceholder.typicode.com/posts
ccsh> curl -X DELETE http://jsonplaceholder.typicode.com/posts/1
ccsh> curl -X POST http://jsonplaceholder.typicode.com/posts -d {"title":"foo"}
ccsh> curl -X PUT http://jsonplaceholder.typicode.com/posts/1 -d {"title":"bar"}
ccsh> curl -v -X GET https://jsonplaceholder.typicode.com/posts/1

Keyboard Shortcuts

↑ / ↓Navigate command history
← / →Move cursor in current input
EnterExecute command
Home / Pos1Jump to start of line
EndJump to end of line
BackspaceDelete character left of cursor
DeleteDelete character right of cursor

History

Persistence — On exit, the current session's command history is written to .ccsh_history in the user's home directory. On the next start, this file is read back automatically, making previous commands immediately available via ↑ ↓.

Raw Input

Canonical mode problem — Unix/Linux/macOS consoles default to canonical (cooked) mode, buffering input line-by-line. This prevents detection of arrow keys and individual keystrokes. RawConsoleInput switches the terminal into non-canonical (raw) mode via JNA.
Windows — Uses _kbhit() and _getwch() from msvcrt.dll. Disables ENABLE_LINE_INPUT and ENABLE_ECHO_INPUT, and enables ENABLE_VIRTUAL_TERMINAL_INPUT / ENABLE_VIRTUAL_TERMINAL_PROCESSING for ANSI support in cmd.exe.
Linux / macOS — Uses tcsetattr() to enter raw mode and System.in.read() for direct byte reading. A CharsetDecoder handles correct multi-byte character translation. Call resetConsoleMode() before mixing with normal line-mode input.

Known Limitations

  • No wildcard support (*, ?)
  • No environment variables ($HOME, $PATH)
  • No tab completion
  • Pipe exchange limited to List<String> — curl cannot be piped

License

LGPL
v2.1
GNU Lesser General Public License v2.1.
You may use, modify and distribute this software under the terms of the LGPL.