-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a WS server for a live REPL (#61)
In this PR: - [x] Add serde - [x] Add serde_json - [x] Implement `Serialize` and `Deserialize` on all public types - [x] Add a `serve` option to `stack-cli`
- Loading branch information
Showing
19 changed files
with
991 additions
and
147 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use core::fmt; | ||
use std::io::{self, prelude::Write}; | ||
|
||
use crossterm::{ | ||
cursor::{self, MoveTo}, | ||
style::Print, | ||
terminal, QueueableCommand, | ||
}; | ||
use stack_core::prelude::*; | ||
|
||
pub mod server; | ||
|
||
pub fn ok_or_exit<T, E>(result: Result<T, E>) -> T | ||
where | ||
E: fmt::Display, | ||
{ | ||
match result { | ||
Ok(x) => x, | ||
Err(e) => { | ||
eprintln!("error: {e}"); | ||
std::process::exit(1); | ||
} | ||
} | ||
} | ||
|
||
pub fn print_stack(context: &Context) { | ||
print!("stack:"); | ||
|
||
core::iter::repeat(" ") | ||
.zip(context.stack()) | ||
.for_each(|(sep, x)| print!("{sep}{x:#}")); | ||
|
||
println!() | ||
} | ||
|
||
pub fn eprint_stack(context: &Context) { | ||
eprint!("stack:"); | ||
|
||
core::iter::repeat(" ") | ||
.zip(context.stack()) | ||
.for_each(|(sep, x)| eprint!("{sep}{x:#}")); | ||
|
||
eprintln!() | ||
} | ||
|
||
pub fn clear_screen() -> io::Result<()> { | ||
let mut stdout = std::io::stdout(); | ||
|
||
stdout.queue(cursor::Hide)?; | ||
let (_, num_lines) = terminal::size()?; | ||
for _ in 0..2 * num_lines { | ||
stdout.queue(Print("\n"))?; | ||
} | ||
stdout.queue(MoveTo(0, 0))?; | ||
stdout.queue(cursor::Show)?; | ||
|
||
stdout.flush() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.