Typstify /chat_message to /chat
This commit is contained in:
parent
8bece23baf
commit
de7ae63a5e
13 changed files with 93 additions and 153 deletions
5
showbits-thermal-printer/src/documents/chat/data.json
Normal file
5
showbits-thermal-printer/src/documents/chat/data.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"username": "John Argbuckle aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
"feed": false
|
||||
}
|
||||
1
showbits-thermal-printer/src/documents/chat/lib
Symbolic link
1
showbits-thermal-printer/src/documents/chat/lib
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../lib
|
||||
37
showbits-thermal-printer/src/documents/chat/main.typ
Normal file
37
showbits-thermal-printer/src/documents/chat/main.typ
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#import "lib/main.typ" as lib;
|
||||
#show: it => lib.init(it)
|
||||
|
||||
#let data = json("data.json")
|
||||
|
||||
#let max_width = 32 * 8pt + 4pt
|
||||
#let limit_width(body) = context {
|
||||
let width = measure(body).width
|
||||
if width > max_width { box(body, width: max_width) } else { body }
|
||||
}
|
||||
|
||||
// This way, the top line of the username box looks better.
|
||||
#v(4pt)
|
||||
|
||||
#par(hanging-indent: 32pt)[
|
||||
#limit_width(
|
||||
box(
|
||||
height: 10pt,
|
||||
clip: true,
|
||||
stroke: 1pt + black,
|
||||
inset: (x: 2pt),
|
||||
outset: (y: 3pt + .5pt, x: -.5pt),
|
||||
{
|
||||
// Ensure all characters that fit on the line are displayed on the line.
|
||||
// We don't want a half-empty box.
|
||||
show regex("."): it => it + sym.zws
|
||||
data.username
|
||||
},
|
||||
),
|
||||
)
|
||||
#h(-4pt)
|
||||
#data.content
|
||||
]
|
||||
|
||||
#if data.feed {
|
||||
lib.feed
|
||||
}
|
||||
38
showbits-thermal-printer/src/documents/chat/mod.rs
Normal file
38
showbits-thermal-printer/src/documents/chat/mod.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use axum::{Form, extract::State};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
drawer::{Command, NewTypstDrawing},
|
||||
server::Server,
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Data {
|
||||
username: String,
|
||||
content: String,
|
||||
feed: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormData {
|
||||
pub username: String,
|
||||
pub content: String,
|
||||
pub feed: Option<bool>,
|
||||
}
|
||||
|
||||
pub async fn post(server: State<Server>, Form(form): Form<FormData>) {
|
||||
let data = Data {
|
||||
username: form.username,
|
||||
content: form.content,
|
||||
feed: form.feed.unwrap_or(false),
|
||||
};
|
||||
|
||||
let typst = super::typst_with_lib()
|
||||
.with_json("/data.json", &data)
|
||||
.with_main_file(include_str!("main.typ"));
|
||||
|
||||
let _ = server
|
||||
.tx
|
||||
.send(Command::draw(NewTypstDrawing::new(typst)))
|
||||
.await;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue