mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-19 02:20:12 +01:00
rustfmt, trucate text width
This commit is contained in:
parent
fd9e5411e2
commit
b219dbefa7
|
@ -23,10 +23,9 @@ impl Display {
|
||||||
pub fn send(&self, cmd: Command) -> Result<()> {
|
pub fn send(&self, cmd: Command) -> Result<()> {
|
||||||
let data: Data = cmd.into();
|
let data: Data = cmd.into();
|
||||||
for frame in data {
|
for frame in data {
|
||||||
self.socket.send_to(
|
self.socket
|
||||||
frame.as_slice(), self.addr.clone().as_str())?;
|
.send_to(frame.as_slice(), self.addr.clone().as_str())?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/// An origin marks the top left position of the
|
/// An origin marks the top left position of the
|
||||||
/// data sent to the display.
|
/// data sent to the display.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -15,4 +14,3 @@ impl Window {
|
||||||
Window(Origin(x, y), Size(w, h))
|
Window(Origin(x, y), Size(w, h))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
mod display;
|
|
||||||
mod protocol;
|
|
||||||
mod commands;
|
mod commands;
|
||||||
|
mod display;
|
||||||
mod geometry;
|
mod geometry;
|
||||||
|
mod protocol;
|
||||||
mod text;
|
mod text;
|
||||||
|
|
||||||
pub const TEXT_COLUMNS: usize = 56;
|
pub const TEXT_COLUMNS: usize = 56;
|
||||||
pub const TEXT_ROWS: usize = 20;
|
pub const TEXT_ROWS: usize = 20;
|
||||||
|
|
||||||
pub use commands::{Command};
|
pub use commands::Command;
|
||||||
pub use protocol::Data;
|
|
||||||
pub use display::Display;
|
pub use display::Display;
|
||||||
|
pub use protocol::Data;
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
use codepage_437::{CP437_WINGDINGS, ToCp437};
|
use codepage_437::{ToCp437, CP437_WINGDINGS};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
commands::{Command},
|
commands::Command,
|
||||||
text,
|
geometry::{Origin, Size, Window},
|
||||||
geometry::{Window, Origin, Size},
|
text, TEXT_COLUMNS, TEXT_ROWS,
|
||||||
TEXT_COLUMNS, TEXT_ROWS,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03];
|
const CMD_RAW_TEXT: &'static [u8] = &[0x00, 0x03];
|
||||||
|
@ -21,20 +20,14 @@ pub type Data = Vec<Frame>;
|
||||||
/// Encode position data as big endian
|
/// Encode position data as big endian
|
||||||
impl From<Origin> for Frame {
|
impl From<Origin> for Frame {
|
||||||
fn from(Origin(x, y): Origin) -> Self {
|
fn from(Origin(x, y): Origin) -> Self {
|
||||||
vec![
|
vec![(x >> 8) as u8, x as u8, (y >> 8) as u8, y as u8]
|
||||||
(x >> 8) as u8, x as u8,
|
|
||||||
(y >> 8) as u8, y as u8,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encode size as big endian
|
/// Encode size as big endian
|
||||||
impl From<Size> for Frame {
|
impl From<Size> for Frame {
|
||||||
fn from(Size(w, h): Size) -> Self {
|
fn from(Size(w, h): Size) -> Self {
|
||||||
vec![
|
vec![(w >> 8) as u8, w as u8, (h >> 8) as u8, h as u8]
|
||||||
(w >> 8) as u8, w as u8,
|
|
||||||
(h >> 8) as u8, h as u8,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,22 +56,30 @@ impl From<text::Buffer> for Data {
|
||||||
|
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
|
// Convert utf8 to codepage 437
|
||||||
if let Ok(bytes) = line.to_cp437(&CP437_WINGDINGS) {
|
if let Ok(bytes) = line.to_cp437(&CP437_WINGDINGS) {
|
||||||
|
let mut bytes: Frame = bytes.into();
|
||||||
|
bytes.truncate(TEXT_COLUMNS);
|
||||||
|
|
||||||
let len = bytes.len() as u16;
|
let len = bytes.len() as u16;
|
||||||
let pos = Origin(x, y + i as u16);
|
let pos = Origin(x, y + i as u16);
|
||||||
let size = Size(len, 1);
|
let size = Size(len, 1);
|
||||||
data.push([
|
data.push(
|
||||||
|
[
|
||||||
Frame::from(CMD_RAW_TEXT),
|
Frame::from(CMD_RAW_TEXT),
|
||||||
pos.into(),
|
pos.into(),
|
||||||
size.into(),
|
size.into(),
|
||||||
bytes.into(),
|
bytes.into(),
|
||||||
].concat());
|
]
|
||||||
|
.concat(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Encode text command
|
||||||
impl From<text::Text> for Data {
|
impl From<text::Text> for Data {
|
||||||
fn from(text: text::Text) -> Data {
|
fn from(text: text::Text) -> Data {
|
||||||
match text {
|
match text {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
use super::geometry::Origin;
|
use super::geometry::Origin;
|
||||||
|
|
||||||
|
|
||||||
/// TextRaw holds bytes and a window
|
/// TextRaw holds bytes and a window
|
||||||
pub struct Raw(pub Origin, pub Vec<u8>);
|
pub struct Raw(pub Origin, pub Vec<u8>);
|
||||||
|
|
||||||
|
@ -14,7 +12,6 @@ impl From<Vec<u8>> for Raw {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// TextBuffer holds a multiline block of utf8 text
|
/// TextBuffer holds a multiline block of utf8 text
|
||||||
/// data and a origin.
|
/// data and a origin.
|
||||||
pub struct Buffer(pub Origin, pub String);
|
pub struct Buffer(pub Origin, pub String);
|
||||||
|
|
Loading…
Reference in a new issue