Add diagnostics spans, CLI/view input feeding, and len/str/int builtins.
Unify bytecode errors with path:line:col, support --stdin-file and live view preset stdin, and ship the S0 standard library with gold coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
31a4b69bbd
commit
30cd39fd8f
25 files changed
+964
-111
No files matched your search
@@ -223,6 +223,45 @@ section.block > h2 {
|
||||
font-weight: 600;
|
||||
margin: 0 0 0.85rem;
|
||||
}
|
||||
.stdin-form {
|
||||
margin: 0 0 1rem;
|
||||
display: grid;
|
||||
gap: 0.45rem;
|
||||
max-width: 36rem;
|
||||
}
|
||||
.stdin-form label {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text);
|
||||
}
|
||||
.stdin-form .hint {
|
||||
color: var(--muted);
|
||||
font-size: 0.8rem;
|
||||
margin-left: 0.35rem;
|
||||
}
|
||||
.stdin-form textarea {
|
||||
font: inherit;
|
||||
font-family: var(--mono);
|
||||
font-size: 0.9rem;
|
||||
padding: 0.65rem 0.75rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
resize: vertical;
|
||||
min-height: 4.5rem;
|
||||
}
|
||||
.stdin-form button {
|
||||
justify-self: start;
|
||||
font: inherit;
|
||||
font-size: 0.9rem;
|
||||
padding: 0.45rem 0.9rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: var(--text);
|
||||
color: var(--bg);
|
||||
cursor: pointer;
|
||||
}
|
||||
.stdin-form button:hover { opacity: 0.88; }
|
||||
.structure {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
@@ -581,6 +620,19 @@ pub fn page_file(files: &[PathBuf], rel: &str, vm: &FileViewModel, links: &LinkM
|
||||
} else {
|
||||
escape(&vm.stderr)
|
||||
};
|
||||
let stdin_panel = match links {
|
||||
LinkMode::Live => format!(
|
||||
r#"<form class="stdin-form" method="get" action="/file">
|
||||
<input type="hidden" name="path" value="{path}"/>
|
||||
<label for="stdin">Preset input <span class="hint">one line per input call</span></label>
|
||||
<textarea id="stdin" name="stdin" rows="3" placeholder="Alice">{stdin}</textarea>
|
||||
<button type="submit">Run with input</button>
|
||||
</form>"#,
|
||||
path = escape(rel),
|
||||
stdin = escape(&vm.preset_stdin),
|
||||
),
|
||||
LinkMode::Static { .. } => String::new(),
|
||||
};
|
||||
let title = Path::new(rel)
|
||||
.file_name()
|
||||
.and_then(|s| s.to_str())
|
||||
@@ -596,6 +648,7 @@ pub fn page_file(files: &[PathBuf], rel: &str, vm: &FileViewModel, links: &LinkM
|
||||
</section>
|
||||
<section class="block">
|
||||
<h2>Execution</h2>
|
||||
{stdin_panel}
|
||||
<div class="out {status}">{out}</div>
|
||||
</section>
|
||||
<section class="block">
|
||||
@@ -608,6 +661,7 @@ pub fn page_file(files: &[PathBuf], rel: &str, vm: &FileViewModel, links: &LinkM
|
||||
status_label = status_label,
|
||||
rel = escape(rel),
|
||||
structure = vm.structure_html,
|
||||
stdin_panel = stdin_panel,
|
||||
out = out_text,
|
||||
source = escape(&vm.source),
|
||||
);
|
||||
|
||||
+16
-4
@@ -14,6 +14,7 @@ use std::process::Command;
|
||||
use anyhow::{bail, Context, Result};
|
||||
use tiny_http::{Header, Method, Request, Response, Server, StatusCode};
|
||||
|
||||
use crate::input_feed::split_stdin_text;
|
||||
use crate::view::html::{escape, page_file, page_index, LinkMode};
|
||||
use crate::view::render::{render_module_structure, FileViewModel};
|
||||
use crate::{run_file_capture, RunOptions};
|
||||
@@ -129,7 +130,7 @@ fn handle(root: &ViewRoot, request: Request) -> Result<()> {
|
||||
if let Some(first) = root.files.first() {
|
||||
let rel = first.to_string_lossy().replace('\\', "/");
|
||||
let resolved = resolve_rel(root, &rel)?;
|
||||
let vm = build_file_view(&resolved, &rel)?;
|
||||
let vm = build_file_view(&resolved, &rel, &[])?;
|
||||
let body = page_file(&root.files, &rel, &vm, &LinkMode::Live);
|
||||
respond_html(request, body)
|
||||
} else {
|
||||
@@ -139,8 +140,10 @@ fn handle(root: &ViewRoot, request: Request) -> Result<()> {
|
||||
}
|
||||
"/file" => {
|
||||
let rel = query_param(query, "path").unwrap_or_default();
|
||||
let stdin_raw = query_param(query, "stdin").unwrap_or_default();
|
||||
let stdin_lines = split_stdin_text(&stdin_raw);
|
||||
let resolved = resolve_rel(root, &rel)?;
|
||||
let vm = build_file_view(&resolved, &rel)?;
|
||||
let vm = build_file_view(&resolved, &rel, &stdin_lines)?;
|
||||
let body = page_file(&root.files, &rel, &vm, &LinkMode::Live);
|
||||
respond_html(request, body)
|
||||
}
|
||||
@@ -156,7 +159,11 @@ fn handle(root: &ViewRoot, request: Request) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn build_file_view(abs: &Path, rel: &str) -> Result<FileViewModel> {
|
||||
pub(crate) fn build_file_view(
|
||||
abs: &Path,
|
||||
rel: &str,
|
||||
stdin_lines: &[String],
|
||||
) -> Result<FileViewModel> {
|
||||
let source = fs::read_to_string(abs).with_context(|| format!("read {}", abs.display()))?;
|
||||
let structure = match crate::load::load_module(abs) {
|
||||
Ok(module) => render_module_structure(&module, &source),
|
||||
@@ -165,7 +172,11 @@ pub(crate) fn build_file_view(abs: &Path, rel: &str) -> Result<FileViewModel> {
|
||||
escape(&tidy_user_error(&format!("{e:#}"), abs, rel))
|
||||
),
|
||||
};
|
||||
let (stdout, stderr, ok) = match run_file_capture(abs, &RunOptions::default()) {
|
||||
let opts = RunOptions {
|
||||
stdin_lines: stdin_lines.to_vec(),
|
||||
..RunOptions::default()
|
||||
};
|
||||
let (stdout, stderr, ok) = match run_file_capture(abs, &opts) {
|
||||
Ok(cap) => (cap.stdout, String::new(), true),
|
||||
Err(e) => (
|
||||
String::new(),
|
||||
@@ -180,6 +191,7 @@ pub(crate) fn build_file_view(abs: &Path, rel: &str) -> Result<FileViewModel> {
|
||||
stdout,
|
||||
stderr,
|
||||
ok,
|
||||
preset_stdin: stdin_lines.join("\n"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ pub fn write_static(opts: OutputOptions) -> Result<()> {
|
||||
for rel_pb in &root.files {
|
||||
let rel = rel_pb.to_string_lossy().replace('\\', "/");
|
||||
let abs = resolve_abs(&root, &rel)?;
|
||||
let mut vm = build_file_view(&abs, &rel)?;
|
||||
let mut vm = build_file_view(&abs, &rel, &[])?;
|
||||
if opts.no_exec {
|
||||
vm.stdout.clear();
|
||||
vm.stderr = "execution skipped (--no-exec)".into();
|
||||
|
||||
@@ -18,6 +18,8 @@ pub struct FileViewModel {
|
||||
pub stdout: String,
|
||||
pub stderr: String,
|
||||
pub ok: bool,
|
||||
/// Text shown in the live-view preset stdin box.
|
||||
pub preset_stdin: String,
|
||||
}
|
||||
|
||||
pub fn render_module_structure(module: &Module, source: &str) -> String {
|
||||
|
||||
Reference in new issue
Block a user