X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/8b8f49b713d64065775fe538232f8639083601bd..HEAD:/lunaix-os/hal/term/lcntls/ansi_cntl.c?ds=inline diff --git a/lunaix-os/hal/term/lcntls/ansi_cntl.c b/lunaix-os/hal/term/lcntls/ansi_cntl.c index a11781e..bc66139 100644 --- a/lunaix-os/hal/term/lcntls/ansi_cntl.c +++ b/lunaix-os/hal/term/lcntls/ansi_cntl.c @@ -1,57 +1,26 @@ -#include - -#include +/** + * @file ansi_cntl.c + * @author Lunaixsky (lunaxisky@qq.com) + * @brief Line controller slave that handle all non-POSIX control code or ANSI + * escape sequence + * @version 0.1 + * @date 2023-11-25 + * + * @copyright Copyright (c) 2023 + * + */ +#include "lcntl.h" +#include #define CTRL_MNEMO(chr) (chr - 'A' + 1) -static inline int -__ansi_actcontrol(struct term* termdev, char chr) +int +__ansi_actcontrol(struct lcntl_state* state, char chr) { - struct linebuffer* lbuf = &termdev->line; - switch (chr) { - case '\0': // EOL - case CTRL_MNEMO('D'): // EOF - return 0; - - case CTRL_MNEMO('C'): // INTR - signal_send(termdev->fggrp, SIGINT); - break; - - case '\r': // CR - termdev->line.ptr = 0; - return 1; - - case '\x08': // ERASE - return line_put_next(lbuf, chr, -1); - - case CTRL_MNEMO('Q'): // QUIT - signal_send(termdev->fggrp, SIGKILL); - return 1; - - case CTRL_MNEMO('Z'): // SUSP - signal_send(termdev->fggrp, SIGSTOP); - return 1; - - default: - if ((int)chr < 32) { - line_put_next(lbuf, '^', 0); - chr += 64; - } - break; + if (chr < 32 && chr != '\n') { + lcntl_put_char(state, '^'); + return lcntl_put_char(state, chr += 64); } - return line_put_next(lbuf, chr, 0); + return lcntl_put_char(state, chr); } - -static size_t -ansi_lcntl_process(struct term* termdev, char* line, size_t len) -{ - size_t i = 0; - while (i < len && __ansi_actcontrol(termdev, line[i])) { - i++; - } - - return i; -} - -struct term_lcntl ansi_line_controller = { .apply = ansi_lcntl_process }; \ No newline at end of file