Errors and file changes
Actionable error blocks and previews of generated or changed files.
Error blocks
An error block says what went wrong, why, and what to run next.
use runemark::{ColorMode, Console, ErrorBlock};
let block = ErrorBlock::new("Required toolchain is unavailable")
.with_explanation("The configured version is not installed.")
.with_remedy("Install the required toolchain:")
.add_command("toolchain install stable");
eprint!("{}", block.render(Console::stderr(ColorMode::Auto)));const { renderError } = require('@casoon/runemark')
// stderr text: pass stream so `color: 'auto'` checks stderr rather than stdout
process.stderr.write(renderError({
heading: 'Required toolchain is unavailable',
explanation: 'The configured version is not installed.',
remedy: 'Install the required toolchain:',
commands: ['toolchain install stable'],
}, { stream: 'stderr' }))File changes
Generators and fixers can summarise what they wrote. Actions: added, modified, deleted, renamed;
each change can carry a short delta such as a size. A change has a single path, so a rename shows
the path it ended up at (-> RENAME src/new.rs), not an old-to-new pair.
use runemark::{ColorMode, Console, DiffBlock, FileAction, FileChange};
let diff = DiffBlock::new()
.add_change(FileChange::new(FileAction::Added, "src/components/Footer.astro").with_delta("+1.2 kB"))
.add_change(FileChange::new(FileAction::Modified, "src/layouts/Layout.astro"))
.add_change(FileChange::new(FileAction::Deleted, "src/legacy/Footer.jsx"));
print!("{}", diff.render(Console::stdout(ColorMode::Auto)));const { renderDiff } = require('@casoon/runemark')
process.stdout.write(renderDiff({
changes: [
{ action: 'added', path: 'src/components/Footer.astro', delta: '+1.2 kB' },
{ action: 'modified', path: 'src/layouts/Layout.astro' },
{ action: 'deleted', path: 'src/legacy/Footer.jsx' },
],
}))Both outputs are rendered in the showcase.