runandlog 0.4.0

CLI / TUI that runs the shell commands in a Markdown file and writes the results back
/* Window styling. Deliberately plain: this is a tool window, not a web page. */

:root {
  /* The page sits a shade behind the cards rather than level with them: with both
     white, a card was told from the page by its border alone and the document read
     as one flat sheet.

     The neutrals carry a little of the accent's hue rather than being grey. Flat
     grey next to a blue accent reads as a screenshot of a disabled window; a few
     points of saturation are enough to make the surfaces look lit without turning
     the window into a coloured thing. */
  --bg: #e3e7f0;
  --card: #fcfdff;
  --fg: #1f2328;
  --muted: #5f6675;
  --border: #ccd3e2;
  --surface: #f0f3fa;
  --accent: #1f6feb;
  /* The same accent at low opacity, for the halo around a running cell. Kept as
     its own variable because a colour cannot be given an alpha in a place that
     only takes `var()`. */
  --accent-soft: rgba(31, 111, 235, 0.25);
  --ok: #1a7f37;
  --error: #cf222e;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Same relationship the other way round: the page is the darker of the two. */
    --bg: #05070e;
    --card: #0d1220;
    --fg: #e6edf3;
    --muted: #8b93a7;
    --border: #2b3346;
    --surface: #151b2a;
    --accent: #4493f8;
    --accent-soft: rgba(68, 147, 248, 0.28);
    --ok: #3fb950;
    --error: #f85149;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  /* No `direction: rtl` here, however tempting it is for keeping the end of a
     long path visible: it moves the leading slash of an absolute path to the
     other end, so /home/x/a.md is drawn as home/x/a.md/. The window title
     carries the file name anyway, and the full path is in the tooltip. */
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.cells {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.cell {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  margin-bottom: 14px;
  overflow: hidden;
}

/* A running cell keeps a breathing halo, so that it is picked out of the list
   from across the window and not only by the label on its button. */
.cell.running {
  border-color: var(--accent);
  animation: cell-pulse 1.6s ease-in-out infinite;
}

@keyframes cell-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 var(--accent-soft);
  }
  50% {
    box-shadow: 0 0 0 4px var(--accent-soft);
  }
}

/* The turning ring in the head of a running cell. */
.spinner {
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spinner-turn 0.8s linear infinite;
}

@keyframes spinner-turn {
  to {
    transform: rotate(360deg);
  }
}

/* Movement is the point of both of these, but it is also what makes a window
   unusable for a reader who cannot take it. The cell stays picked out by its
   border and a steady halo, and the ring by being a ring. */
@media (prefers-reduced-motion: reduce) {
  .cell.running {
    animation: none;
    box-shadow: 0 0 0 3px var(--accent-soft);
  }

  .spinner {
    animation: none;
  }
}

.cell-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.number {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--muted);
  /* Fixed width so the buttons beside it line up whether the number is one digit
     or two, since the numbers carry no brackets to hold a shape of their own. */
  min-width: 1.6em;
  text-align: center;
}

.out {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
}

pre {
  margin: 0;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.result {
  border-top: 1px dashed var(--border);
  background: var(--surface);
  color: var(--muted);
}

/* The output of the command running right now. Bounded and scrolled to its end,
   so that a command printing thousands of lines pushes neither the cells below it
   off the window nor the newest line out of sight. */
.result.live {
  border-top: 1px dashed var(--accent);
  color: var(--fg);
  max-height: 14em;
  overflow-y: auto;
}

/* Said in the stylesheet rather than written into the element: the live block is
   filled with whatever the command prints, and a placeholder put there as text
   would have to be told apart from output on every append. */
.result.live:empty::before {
  content: 'Waiting for output…';
  color: var(--muted);
}

.empty {
  color: var(--muted);
}

.status {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--muted);
}

.status[data-kind='ok'] {
  color: var(--ok);
}

.status[data-kind='error'] {
  color: var(--error);
}