2020-07-20 05:14:27 +01:00
|
|
|
/*
|
|
|
|
* ssheven
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 by cy384 <cy384@cy384.com>
|
|
|
|
* See LICENSE file for details
|
|
|
|
*/
|
|
|
|
|
2020-09-20 02:13:09 +01:00
|
|
|
#include "ssheven.h"
|
2020-07-20 05:14:27 +01:00
|
|
|
#include "ssheven-console.h"
|
2021-01-09 22:22:40 +00:00
|
|
|
#include "ssheven-net.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <Sound.h>
|
2020-07-20 05:14:27 +01:00
|
|
|
|
2021-01-11 22:21:47 +00:00
|
|
|
#include <vterm.h>
|
|
|
|
|
2021-01-23 00:47:48 +00:00
|
|
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
|
|
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
|
|
|
|
2020-09-06 19:34:42 +01:00
|
|
|
char key_to_vterm[256] = { VTERM_KEY_NONE };
|
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
int font_offset = 0;
|
|
|
|
|
2020-09-06 19:34:42 +01:00
|
|
|
void setup_key_translation(void)
|
|
|
|
{
|
|
|
|
// TODO: figure out how to translate the rest of these
|
|
|
|
key_to_vterm[kEnterCharCode] = VTERM_KEY_ENTER;
|
|
|
|
key_to_vterm[kTabCharCode] = VTERM_KEY_TAB;
|
|
|
|
key_to_vterm[kBackspaceCharCode] = VTERM_KEY_BACKSPACE;
|
|
|
|
key_to_vterm[kEscapeCharCode] = VTERM_KEY_ESCAPE;
|
|
|
|
key_to_vterm[kUpArrowCharCode] = VTERM_KEY_UP;
|
|
|
|
key_to_vterm[kDownArrowCharCode] = VTERM_KEY_DOWN;
|
|
|
|
key_to_vterm[kLeftArrowCharCode] = VTERM_KEY_LEFT;
|
|
|
|
key_to_vterm[kRightArrowCharCode] = VTERM_KEY_RIGHT;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_INS;
|
|
|
|
key_to_vterm[kDeleteCharCode] = VTERM_KEY_DEL;
|
|
|
|
key_to_vterm[kHomeCharCode] = VTERM_KEY_HOME;
|
|
|
|
key_to_vterm[kEndCharCode] = VTERM_KEY_END;
|
|
|
|
key_to_vterm[kPageUpCharCode] = VTERM_KEY_PAGEUP;
|
|
|
|
key_to_vterm[kPageDownCharCode] = VTERM_KEY_PAGEDOWN;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_0;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_1;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_2;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_3;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_4;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_5;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_6;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_7;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_8;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_9;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_MULT;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_PLUS;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_COMMA;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_MINUS;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_PERIOD;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_DIVIDE;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_ENTER;
|
|
|
|
//key_to_vterm[0] = VTERM_KEY_KP_EQUAL;
|
|
|
|
}
|
2020-07-20 05:14:27 +01:00
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
inline Rect cell_rect(int x, int y, Rect bounds)
|
2021-01-09 22:22:40 +00:00
|
|
|
{
|
2021-06-02 02:32:51 +01:00
|
|
|
Rect r = { (short) (bounds.top + y * con.cell_height + 2), (short) (bounds.left + x * con.cell_width + 2),
|
|
|
|
(short) (bounds.top + (y+1) * con.cell_height + 2), (short) (bounds.left + (x+1) * con.cell_width + 2) };
|
2021-01-09 22:22:40 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_string(const char* c)
|
|
|
|
{
|
|
|
|
vterm_input_write(con.vterm, c, strlen(c));
|
|
|
|
}
|
|
|
|
|
2020-08-30 02:04:21 +01:00
|
|
|
inline void draw_char(int x, int y, Rect* r, char c)
|
2020-07-20 05:14:27 +01:00
|
|
|
{
|
2021-06-02 02:32:51 +01:00
|
|
|
MoveTo(r->left + 2 + x * con.cell_width, r->top + 2 - font_offset + ((y+1) * con.cell_height));
|
2020-08-18 03:21:38 +01:00
|
|
|
DrawChar(c);
|
|
|
|
}
|
|
|
|
|
2020-08-22 02:29:34 +01:00
|
|
|
void toggle_cursor(void)
|
|
|
|
{
|
|
|
|
con.cursor_state = !con.cursor_state;
|
|
|
|
Rect cursor = cell_rect(con.cursor_x, con.cursor_y, con.win->portRect);
|
|
|
|
InvalRect(&cursor);
|
2020-08-18 03:21:38 +01:00
|
|
|
}
|
|
|
|
|
2020-08-22 02:29:34 +01:00
|
|
|
void check_cursor(void)
|
|
|
|
{
|
2020-09-13 01:16:51 +01:00
|
|
|
long unsigned int now = TickCount();
|
2020-08-22 02:29:34 +01:00
|
|
|
if ((now - con.last_cursor_blink) > GetCaretTime())
|
|
|
|
{
|
|
|
|
toggle_cursor();
|
|
|
|
con.last_cursor_blink = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 03:30:48 +01:00
|
|
|
// convert Quickdraw colors into vterm's ANSI color indexes
|
|
|
|
int qd2idx(int qdc)
|
|
|
|
{
|
|
|
|
switch (qdc)
|
|
|
|
{
|
|
|
|
case blackColor: return 0;
|
|
|
|
case redColor: return 1;
|
|
|
|
case greenColor: return 2;
|
|
|
|
case yellowColor: return 3;
|
|
|
|
case blueColor: return 4;
|
|
|
|
case magentaColor: return 5;
|
|
|
|
case cyanColor: return 6;
|
|
|
|
case whiteColor: return 7;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-20 02:13:09 +01:00
|
|
|
// convert vterm's ANSI color indexes into Quickdraw colors
|
2021-06-02 02:32:51 +01:00
|
|
|
int idx2qd[16] = { blackColor, redColor, greenColor, yellowColor, blueColor, magentaColor, cyanColor, whiteColor, blackColor, redColor, greenColor, yellowColor, blueColor, magentaColor, cyanColor, whiteColor };
|
2020-09-20 02:13:09 +01:00
|
|
|
|
2021-01-23 00:47:48 +00:00
|
|
|
void point_to_cell(Point p, int* x, int* y)
|
|
|
|
{
|
|
|
|
*x = p.h / con.cell_width;
|
|
|
|
*y = p.v / con.cell_height;
|
|
|
|
|
|
|
|
if (*x > con.size_x) *x = con.size_x;
|
|
|
|
if (*y > con.size_y) *y = con.size_y;
|
|
|
|
}
|
|
|
|
|
2021-01-23 17:30:43 +00:00
|
|
|
void clear_selection(void)
|
|
|
|
{
|
|
|
|
con.select_start_x = -1;
|
|
|
|
con.select_start_y = -1;
|
|
|
|
con.select_end_x = -1;
|
|
|
|
con.select_end_y = -1;
|
|
|
|
}
|
|
|
|
|
2021-01-23 00:47:48 +00:00
|
|
|
void damage_selection(void)
|
|
|
|
{
|
|
|
|
// damage all rows that have part of the selection (TODO make this better)
|
|
|
|
Rect topleft = cell_rect(0, MIN(con.select_start_y, con.select_end_y), (con.win->portRect));
|
|
|
|
Rect bottomright = cell_rect(con.size_x, MAX(con.select_start_y, con.select_end_y), (con.win->portRect));
|
|
|
|
|
|
|
|
UnionRect(&topleft, &bottomright, &topleft);
|
|
|
|
InvalRect(&topleft);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_selection_end(void)
|
|
|
|
{
|
2021-03-22 00:21:28 +00:00
|
|
|
static int last_mouse_cell_x = -1;
|
|
|
|
static int last_mouse_cell_y = -1;
|
|
|
|
|
|
|
|
int new_mouse_cell_x;
|
|
|
|
int new_mouse_cell_y;
|
|
|
|
|
2021-01-23 00:47:48 +00:00
|
|
|
Point new_mouse;
|
2021-03-22 00:21:28 +00:00
|
|
|
|
2021-01-23 00:47:48 +00:00
|
|
|
GetMouse(&new_mouse);
|
2021-03-22 00:21:28 +00:00
|
|
|
point_to_cell(new_mouse, &new_mouse_cell_x, &new_mouse_cell_y);
|
|
|
|
|
|
|
|
// only damage the selection if the mouse has moved outside of the last cell
|
|
|
|
if (last_mouse_cell_x != new_mouse_cell_x || last_mouse_cell_y != new_mouse_cell_y)
|
|
|
|
{
|
2021-06-02 04:02:18 +01:00
|
|
|
// damage the old selection
|
|
|
|
damage_selection();
|
|
|
|
|
2021-03-22 00:21:28 +00:00
|
|
|
con.select_end_x = new_mouse_cell_x;
|
|
|
|
con.select_end_y = new_mouse_cell_y;
|
2021-01-23 00:47:48 +00:00
|
|
|
|
2021-03-22 00:21:28 +00:00
|
|
|
last_mouse_cell_x = new_mouse_cell_x;
|
|
|
|
last_mouse_cell_y = new_mouse_cell_y;
|
|
|
|
|
|
|
|
// damage the new selection
|
|
|
|
damage_selection();
|
|
|
|
}
|
2021-01-23 00:47:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 03:00:40 +00:00
|
|
|
inline void prev(int* x, int* y)
|
|
|
|
{
|
|
|
|
if (*x == 0)
|
|
|
|
{
|
|
|
|
*x = con.size_x - 1;
|
|
|
|
*y = (*y) - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = (*x) - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void next(int* x, int* y)
|
|
|
|
{
|
|
|
|
if (*x == con.size_x -1)
|
|
|
|
{
|
|
|
|
*x = 0;
|
|
|
|
*y = (*y) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = (*x) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void select_word(void)
|
|
|
|
{
|
|
|
|
Point mouse;
|
|
|
|
GetMouse(&mouse);
|
|
|
|
|
|
|
|
VTermPos pos;
|
|
|
|
point_to_cell(mouse, &pos.col, &pos.row);
|
|
|
|
pos.col++;
|
|
|
|
|
|
|
|
ScreenCell* vtsc = NULL;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
// scan backwards from mouse click point
|
|
|
|
while (!(pos.col == 0 && pos.row == 0))
|
|
|
|
{
|
|
|
|
prev(&pos.col, &pos.row);
|
|
|
|
|
|
|
|
vtsc = vterm_screen_unsafe_get_cell(con.vts, pos);
|
|
|
|
c = (char)vtsc->chars[0];
|
|
|
|
if (c == '\0' || c == ' ')
|
|
|
|
{
|
|
|
|
next(&pos.col, &pos.row);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
con.select_start_x = pos.col;
|
|
|
|
con.select_start_y = pos.row;
|
|
|
|
|
|
|
|
// scan forwards from mouse click point
|
|
|
|
point_to_cell(mouse, &pos.col, &pos.row);
|
|
|
|
pos.col--;
|
|
|
|
|
|
|
|
while (!(pos.col == con.size_x - 1 && pos.row == con.size_y -1))
|
|
|
|
{
|
|
|
|
next(&pos.col, &pos.row);
|
|
|
|
|
|
|
|
vtsc = vterm_screen_unsafe_get_cell(con.vts, pos);
|
|
|
|
c = (char)vtsc->chars[0];
|
|
|
|
if (c == '\0' || c == ' ')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
con.select_end_x = pos.col;
|
|
|
|
con.select_end_y = pos.row;
|
|
|
|
|
|
|
|
damage_selection();
|
|
|
|
}
|
|
|
|
|
2020-12-22 00:38:12 +00:00
|
|
|
// p is in window local coordinates
|
2021-01-23 00:47:48 +00:00
|
|
|
void mouse_click(Point p, int click)
|
2020-12-22 00:38:12 +00:00
|
|
|
{
|
2021-01-23 00:47:48 +00:00
|
|
|
static Point last_click;
|
2021-03-22 03:00:40 +00:00
|
|
|
static unsigned last_click_time = 0;
|
2021-01-23 00:47:48 +00:00
|
|
|
|
|
|
|
con.mouse_state = click;
|
|
|
|
|
2021-01-11 22:21:47 +00:00
|
|
|
if (con.mouse_mode == CLICK_SEND)
|
2020-12-28 01:44:37 +00:00
|
|
|
{
|
|
|
|
int row = p.v / con.cell_height;
|
|
|
|
int col = p.h / con.cell_width;
|
|
|
|
vterm_mouse_move(con.vterm, row, col, VTERM_MOD_NONE);
|
|
|
|
vterm_mouse_button(con.vterm, 1, click, VTERM_MOD_NONE);
|
|
|
|
}
|
2021-01-11 22:21:47 +00:00
|
|
|
else if (con.mouse_mode == CLICK_SELECT)
|
2020-12-28 01:44:37 +00:00
|
|
|
{
|
2021-01-23 00:47:48 +00:00
|
|
|
if (click)
|
|
|
|
{
|
|
|
|
// damage the old selection so it gets wiped from the screen
|
|
|
|
damage_selection();
|
|
|
|
last_click = p;
|
2021-03-22 03:00:40 +00:00
|
|
|
|
|
|
|
// if it's a double click
|
|
|
|
if (TickCount() - last_click_time < GetDblTime())
|
|
|
|
{
|
|
|
|
select_word();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
point_to_cell(p, &con.select_start_x, &con.select_start_y);
|
|
|
|
point_to_cell(p, &con.select_end_x, &con.select_end_y);
|
|
|
|
|
|
|
|
update_selection_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
last_click_time = TickCount();
|
2021-01-23 00:47:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int a, b, c, d;
|
|
|
|
point_to_cell(last_click, &a, &b);
|
|
|
|
point_to_cell(p, &c, &d);
|
|
|
|
|
|
|
|
// if in same cell, cancel the selection
|
2021-03-22 03:00:40 +00:00
|
|
|
//if (a == c && b == d) clear_selection();
|
2021-01-23 00:47:48 +00:00
|
|
|
|
2021-03-22 03:00:40 +00:00
|
|
|
//update_selection_end();
|
2021-01-23 00:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t get_selection(char** selection)
|
|
|
|
{
|
2021-01-23 17:30:43 +00:00
|
|
|
if (con.select_start_x == -1 || con.select_start_y == -1)
|
2021-01-23 00:47:48 +00:00
|
|
|
{
|
|
|
|
*selection = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-23 17:30:43 +00:00
|
|
|
int a = con.select_start_x + con.select_start_y * con.size_x;
|
|
|
|
int b = con.select_end_x + con.select_end_y * con.size_x;
|
|
|
|
|
|
|
|
ssize_t len = MAX(a,b) - MIN(a,b) + 1;
|
2021-01-23 00:47:48 +00:00
|
|
|
|
|
|
|
char* output = malloc(sizeof(char) * len);
|
|
|
|
|
|
|
|
int start_row = MIN(con.select_start_y, con.select_end_y);
|
|
|
|
int start_col = MIN(con.select_start_x, con.select_end_x);
|
|
|
|
//int end_row = MAX(con.select_start_y, con.select_end_y);
|
|
|
|
//int end_col = MAX(con.select_start_x, con.select_end_x);
|
|
|
|
|
2021-03-22 03:00:56 +00:00
|
|
|
VTermPos pos = {.row = start_row, .col = start_col-1};
|
2021-01-23 00:47:48 +00:00
|
|
|
ScreenCell* vtsc = NULL;
|
|
|
|
|
|
|
|
for(int i = 0; i < len; i++)
|
|
|
|
{
|
2021-03-22 03:00:56 +00:00
|
|
|
next(&pos.col, &pos.row);
|
2021-01-23 00:47:48 +00:00
|
|
|
|
|
|
|
vtsc = vterm_screen_unsafe_get_cell(con.vts, pos);
|
|
|
|
output[i] = (char)vtsc->chars[0];
|
2020-12-28 01:44:37 +00:00
|
|
|
}
|
2021-01-23 00:47:48 +00:00
|
|
|
|
|
|
|
output[len-1] = '\0';
|
|
|
|
|
|
|
|
*selection = output;
|
|
|
|
|
|
|
|
return len;
|
2020-12-22 00:38:12 +00:00
|
|
|
}
|
|
|
|
|
2021-01-23 17:32:17 +00:00
|
|
|
// TODO: find a way to render this once and then just paste it on
|
|
|
|
inline void draw_resize_corner(void)
|
|
|
|
{
|
|
|
|
// draw the grow icon in the bottom right corner, but not the scroll bars
|
|
|
|
// yes, this is really awkward
|
|
|
|
MacRegion bottom_right_corner = { 10, con.win->portRect};
|
|
|
|
MacRegion* brc = &bottom_right_corner;
|
|
|
|
MacRegion** old = con.win->clipRgn;
|
|
|
|
|
|
|
|
bottom_right_corner.rgnBBox.top = bottom_right_corner.rgnBBox.bottom - 15;
|
|
|
|
bottom_right_corner.rgnBBox.left = bottom_right_corner.rgnBBox.right - 15;
|
|
|
|
|
|
|
|
con.win->clipRgn = &brc;
|
|
|
|
DrawGrowIcon(con.win);
|
|
|
|
con.win->clipRgn = old;
|
|
|
|
}
|
|
|
|
|
2020-10-04 18:41:36 +01:00
|
|
|
void draw_screen_color(Rect* r)
|
2020-08-18 03:21:38 +01:00
|
|
|
{
|
|
|
|
// get the intersection of our console region and the update region
|
2020-09-20 02:13:09 +01:00
|
|
|
//Rect bounds = (con.win->portRect);
|
|
|
|
//SectRect(r, &bounds, r);
|
2020-08-18 03:21:38 +01:00
|
|
|
|
2020-09-20 02:13:09 +01:00
|
|
|
// right now we only call this function to redraw the entire screen
|
|
|
|
// so we don't need this (yet)
|
|
|
|
//short minRow = (0 > (r->top - bounds.top) / con.cell_height) ? 0 : (r->top - bounds.top) / con.cell_height;
|
|
|
|
//short maxRow = (con.size_y < (r->bottom - bounds.top + con.cell_height - 1) / con.cell_height) ? con.size_y : (r->bottom - bounds.top + con.cell_height - 1) / con.cell_height;
|
2020-08-18 03:21:38 +01:00
|
|
|
|
2020-09-20 02:13:09 +01:00
|
|
|
//short minCol = (0 > (r->left - bounds.left) / con.cell_width) ? 0 : (r->left - bounds.left) / con.cell_width;
|
|
|
|
//short maxCol = (con.size_x < (r->right - bounds.left + con.cell_width - 1) / con.cell_width) ? con.size_x : (r->right - bounds.left + con.cell_width - 1) / con.cell_width;
|
2020-08-18 03:21:38 +01:00
|
|
|
|
2020-07-24 01:47:02 +01:00
|
|
|
// don't clobber font settings
|
2020-09-20 02:13:09 +01:00
|
|
|
short save_font = qd.thePort->txFont;
|
2020-07-24 01:47:02 +01:00
|
|
|
short save_font_size = qd.thePort->txSize;
|
|
|
|
short save_font_face = qd.thePort->txFace;
|
2020-09-20 02:13:09 +01:00
|
|
|
short save_font_fg = qd.thePort->fgColor;
|
|
|
|
short save_font_bg = qd.thePort->bkColor;
|
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
short minRow = 0;
|
|
|
|
short maxRow = con.size_y;
|
|
|
|
short minCol = 0;
|
|
|
|
short maxCol = con.size_x;
|
2020-09-20 02:13:09 +01:00
|
|
|
|
2020-07-20 05:14:27 +01:00
|
|
|
TextFont(kFontIDMonaco);
|
2021-06-02 02:32:51 +01:00
|
|
|
TextSize(prefs.font_size);
|
2020-07-20 05:14:27 +01:00
|
|
|
TextFace(normal);
|
2021-06-02 02:32:51 +01:00
|
|
|
BackColor(prefs.bg_color);
|
|
|
|
ForeColor(prefs.fg_color);
|
|
|
|
|
|
|
|
//EraseRect(&con.offscreen->portRect);
|
|
|
|
|
2020-10-10 19:16:13 +01:00
|
|
|
TextMode(srcOr);
|
2020-07-20 05:14:27 +01:00
|
|
|
|
2020-08-30 02:04:21 +01:00
|
|
|
short face = normal;
|
2020-08-30 02:14:59 +01:00
|
|
|
Rect cr;
|
2020-08-29 03:14:43 +01:00
|
|
|
|
2020-09-06 20:06:52 +01:00
|
|
|
ScreenCell* vtsc = NULL;
|
|
|
|
VTermPos pos = {.row = 0, .col = 0};
|
|
|
|
|
2021-01-23 00:47:48 +00:00
|
|
|
int i = 0;
|
|
|
|
int select_start = -1;
|
|
|
|
int select_end = -1;
|
|
|
|
|
2021-01-23 17:30:43 +00:00
|
|
|
if (con.mouse_mode == CLICK_SELECT)
|
2021-01-23 00:47:48 +00:00
|
|
|
{
|
2021-01-23 17:30:43 +00:00
|
|
|
if (con.mouse_state) update_selection_end();
|
2021-01-23 00:47:48 +00:00
|
|
|
|
2021-01-23 17:30:43 +00:00
|
|
|
if (con.select_start_x != -1)
|
2021-01-23 00:47:48 +00:00
|
|
|
{
|
2021-01-23 17:30:43 +00:00
|
|
|
int a = con.select_start_x + con.select_start_y * con.size_x;
|
|
|
|
int b = con.select_end_x + con.select_end_y * con.size_x;
|
2021-01-23 00:47:48 +00:00
|
|
|
|
2021-01-23 17:30:43 +00:00
|
|
|
if (a < b)
|
|
|
|
{
|
|
|
|
select_start = a;
|
|
|
|
select_end = b;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
select_start = b;
|
|
|
|
select_end = a;
|
|
|
|
}
|
|
|
|
}
|
2021-01-23 00:47:48 +00:00
|
|
|
}
|
|
|
|
|
2021-01-23 02:19:02 +00:00
|
|
|
char c = 0;
|
2020-09-20 02:13:09 +01:00
|
|
|
for(pos.row = minRow; pos.row < maxRow; pos.row++)
|
2020-08-18 03:21:38 +01:00
|
|
|
{
|
2020-09-20 02:13:09 +01:00
|
|
|
for (pos.col = minCol; pos.col < maxCol; pos.col++)
|
2020-08-22 02:29:34 +01:00
|
|
|
{
|
2020-09-06 20:06:52 +01:00
|
|
|
vtsc = vterm_screen_unsafe_get_cell(con.vts, pos);
|
2021-01-23 17:32:17 +00:00
|
|
|
c = (char)vtsc->chars[0];
|
2020-09-20 02:13:09 +01:00
|
|
|
|
2021-01-23 17:32:17 +00:00
|
|
|
if (vtsc->pen.reverse)
|
|
|
|
{
|
2021-06-02 02:32:51 +01:00
|
|
|
BackColor(idx2qd[vtsc->pen.fg.indexed.idx]);
|
|
|
|
ForeColor(idx2qd[vtsc->pen.bg.indexed.idx]);
|
2021-01-23 17:32:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-02 02:32:51 +01:00
|
|
|
ForeColor(idx2qd[vtsc->pen.fg.indexed.idx]);
|
|
|
|
BackColor(idx2qd[vtsc->pen.bg.indexed.idx]);
|
2021-01-23 17:32:17 +00:00
|
|
|
}
|
2020-09-20 02:13:09 +01:00
|
|
|
|
2020-10-10 19:16:13 +01:00
|
|
|
cr = cell_rect(pos.col, pos.row, *r);
|
|
|
|
EraseRect(&cr);
|
2020-09-06 20:06:52 +01:00
|
|
|
|
2021-01-23 17:32:17 +00:00
|
|
|
if (c == '\0' || c == ' ')
|
|
|
|
{
|
|
|
|
if (i < select_end && i >= select_start)
|
|
|
|
{
|
|
|
|
InvertRect(&cr);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-08-30 02:04:21 +01:00
|
|
|
face = normal;
|
2020-09-06 20:06:52 +01:00
|
|
|
if (vtsc->pen.bold) face |= (condense|bold);
|
|
|
|
if (vtsc->pen.italic) face |= (condense|italic);
|
|
|
|
if (vtsc->pen.underline) face |= underline;
|
2020-08-30 02:04:21 +01:00
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
TextFace(face);
|
2021-01-23 02:19:02 +00:00
|
|
|
draw_char(pos.col, pos.row, r, c);
|
2020-08-30 02:14:59 +01:00
|
|
|
|
2021-01-23 00:47:48 +00:00
|
|
|
if (i < select_end && i >= select_start)
|
|
|
|
{
|
|
|
|
InvertRect(&cr);
|
|
|
|
}
|
|
|
|
i++;
|
2020-08-22 02:29:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do the cursor if needed
|
2020-10-04 18:41:36 +01:00
|
|
|
if (con.cursor_state == 1 &&
|
|
|
|
con.cursor_visible == 1)
|
|
|
|
{
|
|
|
|
Rect cursor = cell_rect(con.cursor_x, con.cursor_y, con.win->portRect);
|
|
|
|
InvertRect(&cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextFont(save_font);
|
|
|
|
TextSize(save_font_size);
|
|
|
|
TextFace(save_font_face);
|
|
|
|
qd.thePort->fgColor = save_font_fg;
|
|
|
|
qd.thePort->bkColor = save_font_bg;
|
|
|
|
|
2021-01-23 17:32:17 +00:00
|
|
|
draw_resize_corner();
|
2020-10-04 18:41:36 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 14:06:52 +00:00
|
|
|
void erase_row(int i)
|
|
|
|
{
|
|
|
|
Rect left = cell_rect(0, i, (con.win->portRect));
|
|
|
|
Rect right = cell_rect(con.size_x, i, (con.win->portRect));
|
|
|
|
|
|
|
|
UnionRect(&left, &right, &left);
|
|
|
|
EraseRect(&left);
|
|
|
|
}
|
2020-10-04 18:41:36 +01:00
|
|
|
|
|
|
|
void draw_screen_fast(Rect* r)
|
|
|
|
{
|
|
|
|
// don't clobber font settings
|
|
|
|
short save_font = qd.thePort->txFont;
|
|
|
|
short save_font_size = qd.thePort->txSize;
|
|
|
|
short save_font_face = qd.thePort->txFace;
|
|
|
|
short save_font_fg = qd.thePort->fgColor;
|
|
|
|
short save_font_bg = qd.thePort->bkColor;
|
|
|
|
|
|
|
|
TextFont(kFontIDMonaco);
|
2021-06-02 02:32:51 +01:00
|
|
|
TextSize(prefs.font_size);
|
2020-10-04 18:41:36 +01:00
|
|
|
TextFace(normal);
|
|
|
|
qd.thePort->bkColor = whiteColor;
|
|
|
|
qd.thePort->fgColor = blackColor;
|
2021-06-02 02:32:51 +01:00
|
|
|
TextMode(srcOr); // or mode is faster for drawing black on white
|
2020-10-04 18:41:36 +01:00
|
|
|
|
2021-01-23 17:30:43 +00:00
|
|
|
int select_start = -1;
|
|
|
|
int select_end = -1;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (con.mouse_mode == CLICK_SELECT)
|
|
|
|
{
|
|
|
|
if (con.mouse_state) update_selection_end();
|
|
|
|
|
|
|
|
if (con.select_start_x != -1)
|
|
|
|
{
|
|
|
|
int a = con.select_start_x + con.select_start_y * con.size_x;
|
|
|
|
int b = con.select_end_x + con.select_end_y * con.size_x;
|
|
|
|
|
|
|
|
if (a < b)
|
|
|
|
{
|
|
|
|
select_start = a;
|
|
|
|
select_end = b;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
select_start = b;
|
|
|
|
select_end = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-23 17:32:17 +00:00
|
|
|
|
2020-10-04 18:41:36 +01:00
|
|
|
ScreenCell* vtsc = NULL;
|
|
|
|
VTermPos pos = {.row = 0, .col = 0};
|
|
|
|
|
2021-01-23 01:37:03 +00:00
|
|
|
char row_text[con.size_x];
|
2021-01-23 02:16:17 +00:00
|
|
|
char row_invert[con.size_x];
|
|
|
|
Rect cr;
|
2021-01-23 01:37:03 +00:00
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
int vertical_offset = r->top + con.cell_height - font_offset + 2;
|
|
|
|
|
2020-10-04 18:41:36 +01:00
|
|
|
for(pos.row = 0; pos.row < con.size_y; pos.row++)
|
|
|
|
{
|
2021-01-28 14:06:52 +00:00
|
|
|
erase_row(pos.row);
|
|
|
|
|
2020-10-04 18:41:36 +01:00
|
|
|
for (pos.col = 0; pos.col < con.size_x; pos.col++)
|
|
|
|
{
|
|
|
|
vtsc = vterm_screen_unsafe_get_cell(con.vts, pos);
|
2021-01-23 01:37:03 +00:00
|
|
|
row_text[pos.col] = (char)vtsc->chars[0];
|
2021-01-23 02:16:17 +00:00
|
|
|
if (row_text[pos.col] == '\0') row_text[pos.col] = ' ';
|
2021-01-23 17:30:43 +00:00
|
|
|
row_invert[pos.col] = vtsc->pen.reverse ^ (i < select_end && i >= select_start);
|
|
|
|
i++;
|
2020-10-04 18:41:36 +01:00
|
|
|
}
|
2021-01-23 01:37:03 +00:00
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
MoveTo(r->left + 2, vertical_offset);
|
2021-01-23 01:37:03 +00:00
|
|
|
DrawText(row_text, 0, con.size_x);
|
2020-10-04 18:41:36 +01:00
|
|
|
|
2021-01-23 02:16:17 +00:00
|
|
|
for (int i = 0; i < con.size_x; i++)
|
2020-10-04 18:41:36 +01:00
|
|
|
{
|
2021-01-23 02:16:17 +00:00
|
|
|
if (row_invert[i])
|
2020-10-04 18:41:36 +01:00
|
|
|
{
|
2021-01-23 02:16:17 +00:00
|
|
|
cr = cell_rect(i, pos.row, con.win->portRect);
|
2020-10-04 18:41:36 +01:00
|
|
|
InvertRect(&cr);
|
|
|
|
}
|
|
|
|
}
|
2021-06-02 02:32:51 +01:00
|
|
|
vertical_offset += con.cell_height;
|
2020-10-04 18:41:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// do the cursor if needed
|
2021-01-23 17:32:17 +00:00
|
|
|
if (con.cursor_state && con.cursor_visible)
|
2020-08-22 02:29:34 +01:00
|
|
|
{
|
|
|
|
Rect cursor = cell_rect(con.cursor_x, con.cursor_y, con.win->portRect);
|
|
|
|
InvertRect(&cursor);
|
2020-08-18 03:21:38 +01:00
|
|
|
}
|
2020-07-24 01:47:02 +01:00
|
|
|
|
|
|
|
TextFont(save_font);
|
|
|
|
TextSize(save_font_size);
|
|
|
|
TextFace(save_font_face);
|
2020-09-20 02:13:09 +01:00
|
|
|
qd.thePort->fgColor = save_font_fg;
|
|
|
|
qd.thePort->bkColor = save_font_bg;
|
2021-01-23 17:32:17 +00:00
|
|
|
|
|
|
|
//draw_resize_corner();
|
2020-07-20 05:14:27 +01:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:22:40 +00:00
|
|
|
void draw_screen(Rect* r)
|
|
|
|
{
|
2021-01-23 17:32:17 +00:00
|
|
|
if (prefs.display_mode == FASTEST)
|
2021-01-09 22:22:40 +00:00
|
|
|
{
|
2021-01-23 17:32:17 +00:00
|
|
|
draw_screen_fast(r);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
draw_screen_color(r);
|
2021-01-09 22:22:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-20 05:14:27 +01:00
|
|
|
void ruler(Rect* r)
|
|
|
|
{
|
|
|
|
char itoc[] = {'0','1','2','3','4','5','6','7','8','9'};
|
|
|
|
|
2020-09-01 03:53:06 +01:00
|
|
|
for (int x = 0; x < con.size_x; x++)
|
|
|
|
for (int y = 0; y < con.size_y; y++)
|
2020-07-20 05:14:27 +01:00
|
|
|
draw_char(x, y, r, itoc[x%10]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int is_printable(char c)
|
|
|
|
{
|
|
|
|
if (c >= 32 && c <= 126) return 1; else return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-24 00:45:01 +01:00
|
|
|
void print_int(int d)
|
|
|
|
{
|
|
|
|
char itoc[] = {'0','1','2','3','4','5','6','7','8','9'};
|
|
|
|
|
|
|
|
char buffer[12] = {0};
|
|
|
|
int i = 10;
|
2020-08-22 20:16:30 +01:00
|
|
|
int negative = 0;
|
2020-07-24 00:45:01 +01:00
|
|
|
|
2020-07-24 00:58:25 +01:00
|
|
|
if (d == 0)
|
|
|
|
{
|
|
|
|
buffer[0] = '0';
|
|
|
|
i = -1;
|
|
|
|
}
|
|
|
|
|
2020-08-22 20:16:30 +01:00
|
|
|
if (d < 0)
|
|
|
|
{
|
|
|
|
negative = 1;
|
|
|
|
d *= -1;
|
|
|
|
}
|
|
|
|
|
2020-07-24 00:45:01 +01:00
|
|
|
for (; d > 0; i--)
|
|
|
|
{
|
|
|
|
buffer[i] = itoc[d % 10];
|
|
|
|
d /= 10;
|
|
|
|
}
|
|
|
|
|
2020-08-22 20:16:30 +01:00
|
|
|
if (negative) buffer[i] = '-';
|
|
|
|
|
|
|
|
print_string(buffer+i+1-negative);
|
2020-07-24 00:45:01 +01:00
|
|
|
}
|
|
|
|
|
2020-07-26 15:13:51 +01:00
|
|
|
void printf_i(const char* str, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, str);
|
|
|
|
|
|
|
|
while (*str != '\0')
|
|
|
|
{
|
|
|
|
if (*str == '%')
|
|
|
|
{
|
|
|
|
str++;
|
|
|
|
switch (*str)
|
|
|
|
{
|
|
|
|
case 'd':
|
|
|
|
print_int(va_arg(args, int));
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
print_string(va_arg(args, char*));
|
2020-08-29 03:14:43 +01:00
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
vterm_input_write(con.vterm, str-1, 1);
|
|
|
|
break;
|
2020-07-26 15:13:51 +01:00
|
|
|
default:
|
|
|
|
va_arg(args, int); // ignore
|
2020-08-29 03:14:43 +01:00
|
|
|
vterm_input_write(con.vterm, str-1, 2);
|
2020-07-26 15:13:51 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-29 03:14:43 +01:00
|
|
|
vterm_input_write(con.vterm, str, 1);
|
2020-07-26 15:13:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2020-08-29 03:14:43 +01:00
|
|
|
int bell(void* user)
|
|
|
|
{
|
|
|
|
SysBeep(30);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user)
|
|
|
|
{
|
|
|
|
// if the cursor is dark, invalidate that location
|
|
|
|
if (con.cursor_state == 1)
|
|
|
|
{
|
|
|
|
Rect inval = cell_rect(con.cursor_x, con.cursor_y, (con.win->portRect));
|
|
|
|
InvalRect(&inval);
|
|
|
|
}
|
|
|
|
|
|
|
|
con.cursor_x = pos.col;
|
|
|
|
con.cursor_y = pos.row;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int damage(VTermRect rect, void *user)
|
|
|
|
{
|
|
|
|
Rect topleft = cell_rect(rect.start_col, rect.start_row, (con.win->portRect));
|
|
|
|
Rect bottomright = cell_rect(rect.end_col, rect.end_row, (con.win->portRect));
|
|
|
|
|
|
|
|
UnionRect(&topleft, &bottomright, &topleft);
|
|
|
|
InvalRect(&topleft);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-08-30 03:17:01 +01:00
|
|
|
int settermprop(VTermProp prop, VTermValue *val, void *user)
|
|
|
|
{
|
|
|
|
switch (prop)
|
|
|
|
{
|
|
|
|
case VTERM_PROP_TITLE: // string
|
|
|
|
set_window_title(con.win, val->string);
|
|
|
|
return 1;
|
2020-09-15 00:54:31 +01:00
|
|
|
case VTERM_PROP_CURSORVISIBLE: // bool
|
|
|
|
con.cursor_visible = val->boolean;
|
|
|
|
return 1;
|
2020-08-30 03:17:01 +01:00
|
|
|
case VTERM_PROP_MOUSE: // number
|
2021-01-11 22:21:47 +00:00
|
|
|
// record whether or not the terminal wants mouse clicks
|
2021-01-22 22:24:08 +00:00
|
|
|
con.mouse_mode = (val->number == VTERM_PROP_MOUSE_CLICK) ? CLICK_SEND : CLICK_SELECT;
|
2021-01-23 17:30:43 +00:00
|
|
|
damage_selection();
|
|
|
|
clear_selection();
|
2021-01-11 22:21:47 +00:00
|
|
|
return 1;
|
2020-08-30 03:17:01 +01:00
|
|
|
case VTERM_PROP_ALTSCREEN: // bool
|
2021-01-11 22:24:45 +00:00
|
|
|
case VTERM_PROP_ICONNAME: // string
|
|
|
|
case VTERM_PROP_REVERSE: //bool
|
|
|
|
case VTERM_PROP_CURSORSHAPE: // number
|
|
|
|
case VTERM_PROP_CURSORBLINK: // bool
|
2020-08-30 03:17:01 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-01 00:25:46 +01:00
|
|
|
void output_callback(const char *s, size_t len, void *user)
|
|
|
|
{
|
|
|
|
ssh_write((char*)s, len);
|
|
|
|
}
|
|
|
|
|
2020-08-29 03:14:43 +01:00
|
|
|
const VTermScreenCallbacks vtscrcb =
|
|
|
|
{
|
|
|
|
.damage = damage,
|
|
|
|
.moverect = NULL,
|
|
|
|
.movecursor = movecursor,
|
2020-08-30 03:17:01 +01:00
|
|
|
.settermprop = settermprop,
|
2020-08-29 03:14:43 +01:00
|
|
|
.bell = bell,
|
|
|
|
.resize = NULL,
|
|
|
|
.sb_pushline = NULL,
|
|
|
|
.sb_popline = NULL
|
|
|
|
};
|
2020-07-20 05:14:27 +01:00
|
|
|
|
2021-06-05 16:10:06 +01:00
|
|
|
void font_size_change()
|
|
|
|
{
|
|
|
|
clear_selection();
|
|
|
|
|
|
|
|
// don't clobber font settings
|
|
|
|
short save_font = qd.thePort->txFont;
|
|
|
|
short save_font_size = qd.thePort->txSize;
|
|
|
|
short save_font_face = qd.thePort->txFace;
|
|
|
|
|
|
|
|
TextFont(kFontIDMonaco);
|
|
|
|
TextSize(prefs.font_size);
|
|
|
|
TextFace(normal);
|
|
|
|
|
|
|
|
FontInfo fi = {0};
|
|
|
|
GetFontInfo(&fi);
|
|
|
|
|
|
|
|
con.cell_height = fi.ascent + fi.descent + fi.leading + 1;
|
|
|
|
font_offset = fi.descent;
|
2021-06-06 18:23:39 +01:00
|
|
|
|
|
|
|
// you'd think this would be the correct way to determine character size
|
|
|
|
// but no
|
|
|
|
//con.cell_width = fi.widMax;
|
|
|
|
|
|
|
|
con.cell_width = CharWidth(' ');
|
2021-06-05 16:10:06 +01:00
|
|
|
|
|
|
|
TextFont(save_font);
|
|
|
|
TextSize(save_font_size);
|
|
|
|
TextFace(save_font_face);
|
|
|
|
|
|
|
|
SizeWindow(con.win, con.cell_width * con.size_x + 4, con.cell_height * con.size_y + 4, true);
|
|
|
|
EraseRect(&(con.win->portRect));
|
|
|
|
InvalRect(&(con.win->portRect));
|
|
|
|
}
|
|
|
|
|
2020-07-20 05:14:27 +01:00
|
|
|
void console_setup(void)
|
|
|
|
{
|
2020-07-24 01:47:02 +01:00
|
|
|
// don't clobber font settings
|
|
|
|
short save_font = qd.thePort->txFont;
|
|
|
|
short save_font_size = qd.thePort->txSize;
|
|
|
|
short save_font_face = qd.thePort->txFace;
|
|
|
|
|
2020-09-01 03:53:06 +01:00
|
|
|
con.size_x = 80;
|
|
|
|
con.size_y = 24;
|
|
|
|
|
2020-07-20 05:14:27 +01:00
|
|
|
TextFont(kFontIDMonaco);
|
2021-06-02 02:32:51 +01:00
|
|
|
TextSize(prefs.font_size);
|
2020-07-20 05:14:27 +01:00
|
|
|
TextFace(normal);
|
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
FontInfo fi = {0};
|
|
|
|
GetFontInfo(&fi);
|
|
|
|
|
|
|
|
con.cell_height = fi.ascent + fi.descent + fi.leading + 1;
|
|
|
|
font_offset = fi.descent;
|
2021-07-14 00:27:41 +01:00
|
|
|
con.cell_width = CharWidth(' ');
|
2020-07-20 05:14:27 +01:00
|
|
|
|
2020-07-24 01:47:02 +01:00
|
|
|
TextFont(save_font);
|
|
|
|
TextSize(save_font_size);
|
|
|
|
TextFace(save_font_face);
|
|
|
|
|
2020-07-20 05:14:27 +01:00
|
|
|
Rect initial_window_bounds = qd.screenBits.bounds;
|
2021-06-02 02:32:51 +01:00
|
|
|
|
2020-07-20 05:14:27 +01:00
|
|
|
InsetRect(&initial_window_bounds, 20, 20);
|
|
|
|
initial_window_bounds.top += 40;
|
|
|
|
|
2021-06-02 02:32:51 +01:00
|
|
|
initial_window_bounds.bottom = initial_window_bounds.top + con.cell_height * con.size_y + 4;
|
2020-09-01 03:53:06 +01:00
|
|
|
initial_window_bounds.right = initial_window_bounds.left + con.cell_width * con.size_x + 4;
|
2020-07-20 05:14:27 +01:00
|
|
|
|
|
|
|
ConstStr255Param title = "\pssheven " SSHEVEN_VERSION;
|
|
|
|
|
2020-09-01 03:53:06 +01:00
|
|
|
WindowPtr win = NewWindow(NULL, &initial_window_bounds, title, true, documentProc, (WindowPtr)-1, true, 0);
|
2020-07-20 05:14:27 +01:00
|
|
|
|
|
|
|
Rect portRect = win->portRect;
|
|
|
|
|
|
|
|
SetPort(win);
|
|
|
|
EraseRect(&portRect);
|
|
|
|
|
|
|
|
con.win = win;
|
|
|
|
|
|
|
|
con.cursor_x = 0;
|
|
|
|
con.cursor_y = 0;
|
|
|
|
|
2020-09-01 03:53:06 +01:00
|
|
|
con.vterm = vterm_new(con.size_y, con.size_x);
|
2020-08-29 03:14:43 +01:00
|
|
|
vterm_set_utf8(con.vterm, 0);
|
|
|
|
VTermState* vtermstate = vterm_obtain_state(con.vterm);
|
|
|
|
vterm_state_reset(vtermstate, 1);
|
2020-08-18 03:21:38 +01:00
|
|
|
|
2020-09-20 02:13:09 +01:00
|
|
|
VTermColor fg = { .type = VTERM_COLOR_INDEXED };
|
2020-10-04 03:30:48 +01:00
|
|
|
fg.indexed.idx = qd2idx(prefs.fg_color);
|
2020-09-20 02:13:09 +01:00
|
|
|
|
|
|
|
VTermColor bg = { .type = VTERM_COLOR_INDEXED };
|
2020-10-04 03:30:48 +01:00
|
|
|
bg.indexed.idx = qd2idx(prefs.bg_color);
|
2020-09-20 02:13:09 +01:00
|
|
|
|
|
|
|
vterm_state_set_default_colors(vtermstate, &fg, &bg);
|
|
|
|
|
2020-09-01 03:53:06 +01:00
|
|
|
vterm_output_set_callback(con.vterm, output_callback, NULL);
|
|
|
|
|
2020-08-29 03:14:43 +01:00
|
|
|
con.vts = vterm_obtain_screen(con.vterm);
|
|
|
|
vterm_screen_reset(con.vts, 1);
|
|
|
|
vterm_screen_set_callbacks(con.vts, &vtscrcb, NULL);
|
2020-09-06 19:34:42 +01:00
|
|
|
|
|
|
|
setup_key_translation();
|
2020-08-18 03:21:38 +01:00
|
|
|
}
|
2020-08-29 03:14:43 +01:00
|
|
|
|
2020-10-04 17:19:49 +01:00
|
|
|
// TODO: make this update all the cells with the default colors
|
|
|
|
void update_console_colors(void)
|
|
|
|
{
|
|
|
|
VTermState* vtermstate = vterm_obtain_state(con.vterm);
|
|
|
|
|
|
|
|
VTermColor fg = { .type = VTERM_COLOR_INDEXED };
|
|
|
|
fg.indexed.idx = qd2idx(prefs.fg_color);
|
|
|
|
|
|
|
|
VTermColor bg = { .type = VTERM_COLOR_INDEXED };
|
|
|
|
bg.indexed.idx = qd2idx(prefs.bg_color);
|
|
|
|
|
|
|
|
vterm_state_set_default_colors(vtermstate, &fg, &bg);
|
|
|
|
|
|
|
|
InvalRect(&(con.win->portRect));
|
|
|
|
}
|
|
|
|
|