Skip to content

Commit

Permalink
move key event logic to monitor.c
Browse files Browse the repository at this point in the history
  • Loading branch information
anoushk1234 committed Jan 7, 2025
1 parent 67e0461 commit ee87073
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/app/fdctl/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <signal.h>
#include <sys/syscall.h>
#include <linux/capability.h>
#include <termios.h>
#include <fcntl.h>

void
monitor_cmd_args( int * pargc,
Expand Down Expand Up @@ -293,9 +295,20 @@ run_monitor( config_t * const config,
if( FD_UNLIKELY( (ulong)n>=buf_sz ) ) FD_LOG_ERR(( "snprintf truncated" )); \
buf += n; buf_sz -= (ulong)n; \
} while(0)
#define TAB 9
ulong line_count = 0;
int monitor_pane = 0;
/* Disables character echo and canonical mode since we want the input to be processes immediately.*/
struct termios terminal_config;
if( FD_UNLIKELY( 0!=tcgetattr(STDIN_FILENO, &terminal_config) ) ) FD_LOG_ERR(( "tcgetattr failed" ));

terminal_config.c_lflag &= (tcflag_t)~(ICANON | ECHO);
if( FD_UNLIKELY( 0!=tcsetattr(STDIN_FILENO, TCSANOW, &terminal_config) ) ) FD_LOG_ERR(( "tcsetattr failed" ));

/* Terminal also set to non blocking in case the user doesn't send any input. */
int terminal_flag = fcntl(STDIN_FILENO, F_GETFL, 0);
if( FD_UNLIKELY( -1==terminal_flag ) ) FD_LOG_ERR(( "fcntl get flag failed" ));
if( FD_UNLIKELY( -1==fcntl(STDIN_FILENO, F_SETFL, terminal_flag | O_NONBLOCK) ) ) FD_LOG_ERR(( "fcntl set flag failed" ));

for(;;) {
/* Wait a somewhat randomized amount and then make a diagnostic
snapshot */
Expand All @@ -311,6 +324,7 @@ run_monitor( config_t * const config,
char * buf = buffer;
ulong buf_sz = FD_MONITOR_TEXT_BUF_SZ;


/* move to beginning of line, n lines ago */
PRINT( "\033[2J\033[%luF", line_count );

Expand All @@ -325,7 +339,7 @@ run_monitor( config_t * const config,

char * mon_start = buf;
if( FD_UNLIKELY( drain_output_fd >= 0 ) ) PRINT( TEXT_NEWLINE );
if( FD_UNLIKELY(fd_getch() == TAB) ) monitor_pane = !monitor_pane;
if( FD_UNLIKELY(getchar() == '\t') ) monitor_pane = !monitor_pane;

long dt = now-then;

Expand Down

0 comments on commit ee87073

Please sign in to comment.