improve announce example
This commit is contained in:
		
							parent
							
								
									dbbe631741
								
							
						
					
					
						commit
						f7fddda8f1
					
				
					 1 changed files with 16 additions and 10 deletions
				
			
		|  | @ -6,16 +6,26 @@ use servicepoint::{CharGrid, Command, Connection, Cp437Grid, Origin}; | |||
| 
 | ||||
| #[derive(Parser, Debug)] | ||||
| struct Cli { | ||||
|     #[arg(short, long, default_value = "localhost:2342")] | ||||
|     #[arg(
 | ||||
|         short, | ||||
|         long, | ||||
|         default_value = "localhost:2342", | ||||
|         help = "Address of the display" | ||||
|     )] | ||||
|     destination: String, | ||||
|     #[arg(short, long, num_args = 1.., value_delimiter = '\n')] | ||||
|     #[arg(short, long, num_args = 1.., value_delimiter = '\n',
 | ||||
|         help = "Text to send - specify multiple times for multiple lines")] | ||||
|     text: Vec<String>, | ||||
|     #[arg(short, long, default_value_t = true)] | ||||
|     #[arg(
 | ||||
|         short, | ||||
|         long, | ||||
|         default_value_t = true, | ||||
|         help = "Clear screen before sending text" | ||||
|     )] | ||||
|     clear: bool, | ||||
| } | ||||
| 
 | ||||
| /// example: `cargo run -- --text "Hallo,
 | ||||
| /// CCCB"`
 | ||||
| /// example: `cargo run -- --text "Hallo" --text "CCCB"`
 | ||||
| fn main() { | ||||
|     let mut cli = Cli::parse(); | ||||
|     if cli.text.is_empty() { | ||||
|  | @ -31,11 +41,7 @@ fn main() { | |||
|             .expect("sending clear failed"); | ||||
|     } | ||||
| 
 | ||||
|     let text = cli.text.iter().fold(String::new(), move |str, line| { | ||||
|         let is_first = str.is_empty(); | ||||
|         str + if is_first { "" } else { "\n" } + line | ||||
|     }); | ||||
| 
 | ||||
|     let text = cli.text.join("\n"); | ||||
|     let grid = CharGrid::from(&*text); | ||||
|     let cp437_grid = Cp437Grid::from(&grid); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter