void TermView::_Init() { SetFont(be_fixed_font); font_height height; GetFontHeight(&height); fFontHeight = (int)(ceilf(height.ascent) + ceilf(height.descent) + ceilf(height.leading)); fFontWidth = (int)be_fixed_font->StringWidth("X"); fTerm = vterm_new(kDefaultHeight, kDefaultWidth); fTermScreen = vterm_obtain_screen(fTerm); vterm_screen_set_callbacks(fTermScreen, &sScreenCallbacks, this); vterm_screen_reset(fTermScreen, 1); vterm_parser_set_utf8(fTerm, 1); VTermScreenCell cell; VTermPos firstPos; firstPos.row = 0; firstPos.col = 0; _GetCell(firstPos, cell); rgb_color background; background.red = cell.bg.red; background.green = cell.bg.green; background.blue = cell.bg.blue; background.alpha = 255; SetViewColor(background); SetLineTerminator("\n"); }
int vterm_init(vterm_state_t *s, int width, int height, volatile uint16_t *buffer) { memset(s, 0, sizeof(vterm_state_t)); s->magic = VTERM_MAGIC; s->width = width; s->height = height; s->buffer = buffer; s->fgColour = VTERM_LIGHT_GRAY; s->bgColour = VTERM_BLACK; s->autoRenderUpdate = true; /* Initialise virtual terminal. */ dprintf("Initialising %d x %d Virtual Terminal object...\n", width, height); s->vt = vterm_new(s->height, s->width); if (!s->vt) { ROS_ERROR("Failed to create terminal.\n"); return EINVALID; } /* Grab the virtual screen & state object. */ s->vts = vterm_obtain_screen(s->vt); s->vtstate = vterm_obtain_state(s->vt); assert(s->vts && s->vtstate); /* Set parameters. */ vterm_parser_set_utf8(s->vt, true); vterm_state_set_bold_highbright(s->vtstate, true); vterm_screen_reset(s->vts, 1); return ESUCCESS; }
int main(int argc, char *argv[]) { int use_colour = isatty(1); int opt; while((opt = getopt(argc, argv, "c")) != -1) { switch(opt) { case 'c': use_colour = 1; break; } } const char *file = argv[optind++]; int fd; if(!file || streq(file, "-")) fd = 0; // stdin else { fd = open(file, O_RDONLY); if(fd == -1) { fprintf(stderr, "Cannot open %s - %s\n", file, strerror(errno)); exit(1); } } if(use_colour) { special_begin = "\x1b[7m{"; special_end = "}\x1b[m"; } /* Size matters not for the parser */ VTerm *vt = vterm_new(25, 80); vterm_set_utf8(vt, 1); vterm_parser_set_callbacks(vt, &parser_cbs, NULL); int len; char buffer[1024]; while((len = read(fd, buffer, sizeof(buffer))) > 0) { vterm_input_write(vt, buffer, len); } printf("\n"); close(fd); vterm_free(vt); return 0; }
TermView::TermView() : BView("TermView", B_WILL_DRAW | B_FRAME_EVENTS) { SetFont(be_fixed_font); font_height height; GetFontHeight(&height); fFontHeight = height.ascent + height.descent + height.leading; fFontWidth = be_fixed_font->StringWidth("X"); fTerm = vterm_new(kDefaultHeight, kDefaultWidth); fTermScreen = vterm_obtain_screen(fTerm); vterm_screen_set_callbacks(fTermScreen, &sScreenCallbacks, this); vterm_screen_reset(fTermScreen, 1); vterm_parser_set_utf8(fTerm, 1); }
void term_init(struct aug_term *term, int rows, int cols) { VTermScreen *vts; VTermState *state; term->master = 0; term->vt = vterm_new(rows, cols); state = vterm_obtain_state(term->vt); /* have to cast default_color because the api isnt const correct */ vterm_state_set_default_colors(state, &VTERM_DEFAULT_COLOR, &VTERM_DEFAULT_COLOR); vterm_parser_set_utf8(term->vt, 1); vts = vterm_obtain_screen(term->vt); vterm_screen_enable_altscreen(vts, 1); vterm_screen_set_damage_merge(vts, VTERM_DAMAGE_SCROLL); vterm_screen_reset(vts, 1); term_inject_clear(term); term->user = NULL; term->io_callbacks.refresh = NULL; AUG_LOCK_INIT(term); }
VTermMM::VTermMM(int rows, int columns) : fd(0), foreground(VTERMMM_WHITE), background(VTERMMM_BLACK), cells(rows, vrow(columns)), reverse(false), invalid_region() { for(int row = 0; row < rows; ++row) { for(int col = 0; col < columns; ++col) { cells[row][col].SetX(col); cells[row][col].SetY(row); } } cursor.row = 0; cursor.col = 0; invalidate(0, rows, 0, columns); _term = vterm_new(rows, columns); vterm_parser_set_utf8(_term, 1); VTermState *vts = vterm_obtain_state(_term); vterm_state_set_callbacks(vts, &vterm_callbacks, this); }
GLTerminal* init_gl_term() { int rc=0; GLTerminal* term = (GLTerminal*)malloc(sizeof(GLTerminal)); term->fd_master = posix_openpt(O_RDWR); if(term->fd_master < 0) { fprintf(stderr,"Error %d in posix_openpt()\n",errno); free(term); return NULL; } rc = grantpt(term->fd_master); if(rc != 0) { fprintf(stderr,"Error %d on grantpt()\n",errno); free(term); return NULL; } rc = unlockpt(term->fd_master); if(rc != 0) { fprintf(stderr,"Error %d on unlockpt()\n",errno); free(term); return NULL; } term->fd_slave = open(ptsname(term->fd_master), O_RDWR); term->vt = vterm_new(25,80); vterm_set_utf8(term->vt, false); term->vts = vterm_obtain_screen(term->vt); vterm_screen_reset(term->vts,1); int i=0; for(i=0; i<80*25; i++) vterm_input_write(term->vt," ",1); term->render_target_fb=0; // setup font glGenTextures(1,&(term->font_texture)); glBindTexture(GL_TEXTURE_2D, term->font_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, Console_FontData.width, Console_FontData.height, 0, GL_RGB, GL_UNSIGNED_BYTE, Console_FontData.pixel_data); // configure render target glGenFramebuffers(1,&(term->render_target_fb)); glBindFramebuffer(GL_FRAMEBUFFER,term->render_target_fb); GLuint tex_id; glGenTextures(1,&tex_id); term->render_target = tex_id; glBindTexture(GL_TEXTURE_2D,tex_id); glTexImage2D(GL_TEXTURE_2D, 0,3, TERM_SIZE, TERM_SIZE, 0,GL_RGB, GL_UNSIGNED_BYTE,NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, term->render_target,0); GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1,DrawBuffers); glBindFramebuffer(GL_FRAMEBUFFER,0); return term; }
int fbterm_init(struct fbterm_ctx *ctx) { if (!font) { font = font_open(DEFAULT_FONT); if (!font) return -1; } memset(ctx, 0, sizeof(struct fbterm_ctx)); ctx->font = font; fb_term_init(ctx); fb_cook_wallpaper(ctx, DEFAULT_WALLPAPER); VTerm *vt = vterm_new(ctx->rows, ctx->cols); ctx->vt = vt; VTermScreen *sc = vterm_obtain_screen(vt); vterm_screen_set_callbacks(sc, &screen_cbs, ctx); vterm_screen_reset(sc, 0); ctx->screen = sc; VTermRect r = {.start_row = 0, .end_row = ctx->rows, .start_col = 0, .end_col = ctx->cols}; damage(r, ctx); return 0; } int kbd_fd = -1; int pty = -1; int fbterm_main() { struct fbterm_ctx *active = &term[0]; struct winsize ws; ws.ws_row = active->rows; ws.ws_col = active->cols; ioctl(pty, TIOCSWINSZ, &ws); fbterm_redraw(active); size_t len; char buf[1024]; while (1) { /* Read input */ if ((len = read(pty, buf, sizeof(buf))) > 0) { vterm_input_write(active->vt, buf, len); } fbterm_redraw(active); /* Write output */ while (vterm_output_get_buffer_current(active->vt) > 0) { size_t s = vterm_output_read(active->vt, buf, 1024); write(pty, buf, s); } } return 0; } char *pts_fn = NULL; /* XXX */ void launch_shell() { int shell_pid = 0; relaunch: if (shell_pid = fork()) { /* Relaunch shell if died */ int s, pid; do { pid = waitpid(shell_pid, &s, 0); } while (pid != shell_pid); /* Uh..Oh shell died */ goto relaunch; } else { for (int i = 0; i < 10; ++i) close(i); int stdin_fd = open(pts_fn, O_RDONLY); int stdout_fd = open(pts_fn, O_WRONLY); int stderr_fd = open(pts_fn, O_WRONLY); /* run login shell */ char *argp[] = {DEFAULT_SHELL, "login", NULL}; char *envp[] = {"PWD=/", "TERM=VT100", NULL}; execve(DEFAULT_SHELL, argp, envp); for (;;); } }