add command for protocols
This commit is contained in:
parent
232fe6b6e2
commit
b52af7d44f
2 changed files with 22 additions and 1 deletions
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
grid::{self, Flut},
|
||||
increment_counter,
|
||||
protocols::{BinaryParser, IOProtocol, Parser, Responder, TextParser},
|
||||
set_pixel_rgba, Canvas, Color, Command, Coordinate, Protocol, Response,
|
||||
set_pixel_rgba, Canvas, Color, Command, Coordinate, Protocol, ProtocolStatus, Response,
|
||||
};
|
||||
|
||||
macro_rules! build_parser_type_enum {
|
||||
|
|
@ -36,6 +36,17 @@ macro_rules! build_parser_type_enum {
|
|||
}
|
||||
|
||||
impl ParserTypes {
|
||||
pub fn get_status() -> Vec<ProtocolStatus> {
|
||||
let mut protos = Vec::new();
|
||||
$(
|
||||
#[cfg(feature = $feat)]
|
||||
protos.push(ProtocolStatus::Enabled($feat));
|
||||
#[cfg(not(feature = $feat))]
|
||||
protos.push(ProtocolStatus::Disabled($feat));
|
||||
)*
|
||||
protos
|
||||
}
|
||||
|
||||
pub fn announce() {
|
||||
$(
|
||||
#[cfg(feature = $feat)]
|
||||
|
|
@ -88,6 +99,14 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn protocols_command(&mut self) -> io::Result<()> {
|
||||
match_parser! {
|
||||
parser: self.parser => parser.unparse(Response::Protocols(ParserTypes::get_status()), &mut self.writer).await?
|
||||
};
|
||||
self.writer.flush().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn size_command(&mut self, canvas: Canvas) -> io::Result<()> {
|
||||
let (x, y) = self.grids[canvas as usize].get_size();
|
||||
match_parser!(parser: self.parser => parser.unparse(
|
||||
|
|
@ -166,6 +185,7 @@ where
|
|||
match parsed {
|
||||
Ok(Command::Help) => self.help_command().await?,
|
||||
Ok(Command::Size(canvas)) => self.size_command(canvas).await?,
|
||||
Ok(Command::Protocols) => self.protocols_command().await?,
|
||||
Ok(Command::GetPixel(canvas, x, y)) => self.get_pixel_command(canvas, x, y).await?,
|
||||
Ok(Command::SetPixel(canvas, x, y, color)) => self.set_pixel_command(canvas, x, y, &color),
|
||||
Ok(Command::ChangeCanvas(canvas)) => {
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ pub enum Protocol {
|
|||
#[derive(Debug, PartialEq)]
|
||||
pub enum Command {
|
||||
Help,
|
||||
Protocols,
|
||||
Size(Canvas),
|
||||
GetPixel(Canvas, Coordinate, Coordinate),
|
||||
SetPixel(Canvas, Coordinate, Coordinate, Color),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue