void tty_cmd_clearstartofscreen(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; u_int i, j; tty_reset(tty); tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); tty_cursor_pane(tty, ctx, 0, 0); if (ctx->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { for (i = 0; i < ctx->ocy; i++) { tty_putcode(tty, TTYC_EL); tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); tty->cy++; } } else { for (j = 0; j < ctx->ocy; j++) { tty_cursor_pane(tty, ctx, 0, j); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, ' '); } } for (i = 0; i <= ctx->ocx; i++) tty_putc(tty, ' '); }
int mp3anywhere_init(void) { signal_length=hw.code_length*1000000/9600; if(!tty_create_lock(hw.device)) { logprintf(LOG_ERR,"could not create lock files"); return(0); } if((hw.fd=open(hw.device,O_RDWR|O_NONBLOCK|O_NOCTTY))<0) { logprintf(LOG_ERR,"could not open %s",hw.device); logperror(LOG_ERR,"mp3anywhere_init()"); tty_delete_lock(); return(0); } if(!tty_reset(hw.fd)) { logprintf(LOG_ERR,"could not reset tty"); mp3anywhere_deinit(); return(0); } if(!tty_setbaud(hw.fd,9600)) { logprintf(LOG_ERR,"could not set baud rate"); mp3anywhere_deinit(); return(0); } return(1); }
void tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; if (ctx->ocy != ctx->orlower) return; if (ctx->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { tty_redraw_region(tty, ctx); return; } /* * If this line wrapped naturally (ctx->num is nonzero), don't do * anything - the cursor can just be moved to the last cell and wrap * naturally. */ if (ctx->num && !(tty->term->flags & TERM_EARLYWRAP)) return; tty_reset(tty); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putc(tty, '\n'); }
void tty_cmd_insertcharacter(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; u_int i; if (ctx->xoff != 0 || screen_size_x(s) < tty->sx) { tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff); return; } tty_reset(tty); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); if (tty_term_has(tty->term, TTYC_ICH) || tty_term_has(tty->term, TTYC_ICH1)) tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ctx->num); else if (tty_term_has(tty->term, TTYC_SMIR) && tty_term_has(tty->term, TTYC_RMIR)) { tty_putcode(tty, TTYC_SMIR); for (i = 0; i < ctx->num; i++) tty_putc(tty, ' '); tty_putcode(tty, TTYC_RMIR); } else tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff); }
/* ** bye_kids(exit-condition) ** ** Shutdown the terminal, clear the signals, and exit */ void bye_kids(int n) { /* reset the tty and exit */ ignoresig(); if (send_reset_init) { if (exit_ca_mode) { tc_putp(exit_ca_mode); } if (initial_stty_query(TTY_XON_XOFF)) { if (enter_xon_mode) { tc_putp(enter_xon_mode); } } else if (exit_xon_mode) { tc_putp(exit_xon_mode); } } if (debug_fp) { fclose(debug_fp); } if (log_fp) { fclose(log_fp); } tty_reset(); fclose(stdin); fclose(stdout); fclose(stderr); if (not_a_tty) sleep(1); ExitProgram(n); }
void tty_attributes(struct tty *tty, const struct grid_cell *gc) { struct grid_cell *tc = &tty->cell; u_char changed; u_int fg, bg; /* If any bits are being cleared, reset everything. */ if (tc->attr & ~gc->attr) tty_reset(tty); /* Filter out attribute bits already set. */ changed = gc->attr & ~tc->attr; tc->attr = gc->attr; /* Set the attributes. */ fg = gc->fg; bg = gc->bg; if (changed & GRID_ATTR_BRIGHT) tty_putcode(tty, TTYC_BOLD); if (changed & GRID_ATTR_DIM) tty_putcode(tty, TTYC_DIM); if (changed & GRID_ATTR_ITALICS) tty_putcode(tty, TTYC_SMSO); if (changed & GRID_ATTR_UNDERSCORE) tty_putcode(tty, TTYC_SMUL); if (changed & GRID_ATTR_BLINK) tty_putcode(tty, TTYC_BLINK); if (changed & GRID_ATTR_REVERSE) { if (tty_term_has(tty->term, TTYC_REV)) tty_putcode(tty, TTYC_REV); else if (tty_term_has(tty->term, TTYC_SMSO)) tty_putcode(tty, TTYC_SMSO); } if (changed & GRID_ATTR_HIDDEN) tty_putcode(tty, TTYC_INVIS); if (changed & GRID_ATTR_CHARSET) tty_putcode(tty, TTYC_SMACS); /* Set foreground colour. */ if (fg != tc->fg || (gc->flags & GRID_FLAG_FG256) != (tc->flags & GRID_FLAG_FG256)) { tty_attributes_fg(tty, gc); tc->fg = fg; tc->flags &= ~GRID_FLAG_FG256; tc->flags |= gc->flags & GRID_FLAG_FG256; } /* Set background colour. */ if (bg != tc->bg || (gc->flags & GRID_FLAG_BG256) != (tc->flags & GRID_FLAG_BG256)) { tty_attributes_bg(tty, gc); tc->bg = bg; tc->flags &= ~GRID_FLAG_BG256; tc->flags |= gc->flags & GRID_FLAG_BG256; } }
int check_tira(void) { logprintf(LOG_ERR, "Searching for Tira"); if(!tty_reset(hw.fd) || !tty_setbaud(hw.fd, 9600) || !tty_setrtscts(hw.fd, 1)) return 0; usleep (50000); return tira_setup(); }
static SIGRETTYPE suspend(int sig) { tty_reset(tty_fd); sys_sigset(sig, SIG_DFL); /* Set signal handler to default */ sys_sigrelease(sig); /* Allow 'sig' to come through */ kill(getpid(), sig); /* Send ourselves the signal */ sys_sigblock(sig); /* Reset to old mask */ sys_sigset(sig, suspend); /* Reset signal handler */ tty_set(tty_fd); }
static SIGRETTYPE ctl_c(int sig) { tty_reset(tty_fd); sys_sigset(sig, orig_ctl_c); /* Set ctl_c break handler to original */ sys_sigrelease(sig); /* Allow 'sig' to come through */ kill(getpid(), sig); /* Send ourselves the signal */ sys_sigblock(sig); /* Reset to old mask */ sys_sigset(sig, ctl_c); /* Reset signal handler */ tty_set(tty_fd); }
int main(void) { int i; char c; if (signal(SIGINT, sig_catch) == SIG_ERR) /* catch signals */ err_sys("signal(SIGINT) error"); if (signal(SIGQUIT, sig_catch) == SIG_ERR) err_sys("signal(SIGQUIT) error"); if (signal(SIGTERM, sig_catch) == SIG_ERR) err_sys("signal(SIGTERM) error"); if (tty_raw(STDIN_FILENO) < 0) err_sys("tty_raw error"); printf("Enter raw mode characters, terminate with DELETE\n"); while ((i = read(STDIN_FILENO, &c, 1)) == 1) { if ((c &= 255) == 0177) /* 0177 = ASCII DELETE */ break; printf("%o\n", c); } if (tty_reset(STDIN_FILENO) < 0) err_sys("tty_reset error"); if (i <= 0) err_sys("read error"); if (tty_cbreak(STDIN_FILENO) < 0) err_sys("tty_cbreak error"); printf("\nEnter cbreak mode characters, terminate with SIGINT\n"); while ((i = read(STDIN_FILENO, &c, 1)) == 1) { c &= 255; printf("%o\n", c); } if (tty_reset(STDIN_FILENO) < 0) err_sys("tty_reset error"); if (i <= 0) err_sys("read error"); exit(0); }
void tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) { tty_reset(tty); if (ctx->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) { tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putcode(tty, TTYC_EL1); } else { tty_cursor_pane(tty, ctx, 0, ctx->ocy); tty_repeat_space(tty, ctx->ocx + 1); } }
void tty_destroy(struct tty *tty) { if (tty->input_source) wl_event_source_remove(tty->input_source); wl_event_source_remove(tty->vt_source); tty_reset(tty); close(tty->fd); free(tty); }
int main(int argc, char *argv[]) { atexit(tty_atexit); int i; char c; Signal(SIGINT, sig_catch); Signal(SIGQUIT, sig_catch); Signal(SIGTERM, sig_catch); if(tty_raw(STDIN_FILENO) < 0) err_sys("tty_raw error"); printf("Enter raw mode characters, terminate with DELETE\n"); while ((i = read(STDIN_FILENO, &c, 1)) == 1) { if((c &= 255) == 0177) /* 0177 = ASCII DELETE*/ break; printf("%o\n", c ); } if(tty_reset(STDIN_FILENO) < 0) err_sys("tty_reset error"); if(i <= 0) err_sys("read error"); if(tty_cbreak(STDIN_FILENO) < 0) err_sys("tty_raw error"); printf("\n Enter cbreak mode characters, terminate with SIGINT\n"); while ( (i = read(STDIN_FILENO, &c, 1)) == 1) { c &= 255; printf("%o\n", c); } tty_reset(STDIN_FILENO); if( i < 0) err_sys("read error");; return 0; }
void tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; tty_reset(tty); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); if (tty_pane_full_width(tty, ctx) && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else tty_repeat_space(tty, screen_size_x(s) - ctx->ocx); }
void tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) { u_int i; tty_reset(tty); if (ctx->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) { tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putcode(tty, TTYC_EL1); } else { tty_cursor_pane(tty, ctx, 0, ctx->ocy); for (i = 0; i < ctx->ocx + 1; i++) tty_putc(tty, ' '); } }
void tty_cmd_alignmenttest( struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; u_int i, j; tty_reset(tty); tty_region(tty, 0, screen_size_y(s) - 1, wp->yoff); for (j = 0; j < screen_size_y(s); j++) { tty_cursor(tty, 0, j, wp->xoff, wp->yoff); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, 'E'); } }
void tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx) { if (!tty_pane_full_width(tty, ctx) || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_DL1)) { tty_redraw_region(tty, ctx); return; } tty_reset(tty); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ctx->num); }
static void *watch_tty(struct watch_tty_data *wtd) { struct tcp_spec ts; char buf[256]; int nr; if (wtd->input_mode == INPUT_MODE_RAW) tty_raw(0, 1, 0); while ((nr = read(0, buf, sizeof(buf)))) { if (buf[0] == 29) /* ^] */ break; if (wtd->input_mode == INPUT_MODE_LINEECHO || wtd->input_mode == INPUT_MODE_LINEECHOR) { if (nr >= 3 && buf[0] == '^' && buf[1] == ']' && buf[2] == '\n') break; if (wtd->input_mode == INPUT_MODE_LINEECHOR && nr < sizeof(buf) && buf[nr - 1] == '\n') { buf[nr - 1] = '\r'; buf[nr++] = '\n'; } } memset(&ts, 0, sizeof(ts)); ts.saddr = wtd->ci->src_addr; ts.daddr = wtd->ci->dst_addr; ts.sport = wtd->ci->src_port; ts.dport = wtd->ci->dst_port; ts.src_mac = wtd->src_fake_mac; ts.dst_mac = wtd->ci->dst.src_mac; ts.seq = wtd->ci->dst.next_d_seq; ts.ack_seq = wtd->ci->dst.next_seq; ts.window = wtd->ci->src.window ? wtd->ci->src.window : htons(242); ts.id = htons(ntohs(wtd->ci->src.id) + 1); ts.ack = 1; ts.psh = 1; ts.rst = 0; ts.data = buf; ts.data_len = nr; send_tcp_packet(&ts); } if (wtd->input_mode == INPUT_MODE_RAW) tty_reset(0); list_produce_done(&l_hijack_conn); return NULL; }
void tty_cmd_clearline(struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; u_int i; tty_reset(tty); tty_cursor(tty, 0, s->old_cy, wp->xoff, wp->yoff); if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { tty_putcode(tty, TTYC_EL); } else { for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, ' '); } }
void tty_cmd_alignmenttest(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; u_int i, j; tty_reset(tty); tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1); for (j = 0; j < screen_size_y(s); j++) { tty_cursor_pane(tty, ctx, 0, j); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, 'E'); } }
int main(int argc, char **argv) { treak_init(); char c; while(1) { if ( read(STDIN_FILENO, &c, 1) == 1) { std::cout << "Pressed " << c << "\n"; } } tty_reset(STDIN_FILENO); return 0; }
void tty_cmd_deletecharacter(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; u_int ua; if (wp->xoff != 0 || screen_size_x(s) < tty->sx) { tty_draw_line(tty, wp->screen, s->old_cy, wp->xoff, wp->yoff); return; } ua = va_arg(ap, u_int); tty_reset(tty); tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ua); }
void tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; u_int i; tty_reset(tty); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { for (i = ctx->ocx; i < screen_size_x(s); i++) tty_putc(tty, ' '); } }
void tty_cmd_linefeed(struct tty *tty, struct window_pane *wp, unused va_list ap) { struct screen *s = wp->screen; if (wp->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { tty_redraw_region(tty, wp); return; } tty_reset(tty); tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); if (s->old_cy == s->old_rlower) { tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_putc(tty, '\n'); } }
void tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; if (wp->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_DL1)) { tty_redraw_region(tty, ctx); return; } tty_reset(tty); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ctx->num); }
void tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx) { if (ctx->ocy != ctx->orupper) return; if (!tty_pane_full_width(tty, ctx) || !tty_term_has(tty->term, TTYC_CSR) || !tty_term_has(tty->term, TTYC_RI)) { tty_redraw_region(tty, ctx); return; } tty_reset(tty); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->orupper); tty_putcode(tty, TTYC_RI); }
void tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; if (!tty_pane_full_width(tty, ctx) || (!tty_term_has(tty->term, TTYC_DCH) && !tty_term_has(tty->term, TTYC_DCH1))) { tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff); return; } tty_reset(tty); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); if (tty_term_has(tty->term, TTYC_DCH) || tty_term_has(tty->term, TTYC_DCH1)) tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ctx->num); }
void tty_cmd_deleteline(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; u_int ua; if (wp->xoff != 0 || screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { tty_redraw_region(tty, wp); return; } ua = va_arg(ap, u_int); tty_reset(tty); tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ua); }
void tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) { const struct grid_cell *gc; const struct grid_utf8 *gu; u_int i, sx; sx = screen_size_x(s); if (sx > s->grid->size[s->grid->hsize + py]) sx = s->grid->size[s->grid->hsize + py]; if (sx > tty->sx) sx = tty->sx; tty_cursor(tty, 0, py, ox, oy); for (i = 0; i < sx; i++) { gc = grid_view_peek_cell(s->grid, i, py); gu = NULL; if (gc->flags & GRID_FLAG_UTF8) gu = grid_view_peek_utf8(s->grid, i, py); if (screen_check_selection(s, i, py)) { s->sel.cell.data = gc->data; tty_cell(tty, &s->sel.cell, gu); } else tty_cell(tty, gc, gu); } if (sx >= tty->sx) return; tty_reset(tty); tty_cursor(tty, sx, py, ox, oy); if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { for (i = sx; i < screen_size_x(s); i++) tty_putc(tty, ' '); } }
void tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; struct screen *s = wp->screen; if (ctx->ocy != ctx->orlower) return; if (!tty_pane_full_width(tty, ctx) || !tty_term_has(tty->term, TTYC_CSR)) { if (tty_large_region(tty, ctx)) wp->flags |= PANE_REDRAW; else if (tty_use_rect(tty)) { tty_cra_pane (tty, ctx, ctx->orupper + 1, 0, ctx->orlower, screen_size_x(s) - 1, ctx->orupper, 0); tty_cmd_clearline(tty, ctx); } else tty_redraw_region(tty, ctx); return; } /* * If this line wrapped naturally (ctx->num is nonzero), don't do * anything - the cursor can just be moved to the last cell and wrap * naturally. */ if (ctx->num && !(tty->term->flags & TERM_EARLYWRAP)) return; tty_reset(tty); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_putc(tty, '\n'); }