Skip to content

Commit

Permalink
Allow text editor to start pre-filled
Browse files Browse the repository at this point in the history
Use that for Mastodon replies
  • Loading branch information
colinleroy committed Jul 12, 2023
1 parent 8c2643d commit 742ff85
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
== Testing without serial port ==

How to MOK: https://ursache.io/posts/signed-kernel-module-debian-2023/
```
git clone https://github.com/freemed/tty0tty
cd tty0tty-1.2/module
make
/usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 ../mok/MOK.priv ../mok/MOK.der ./module/tty0tty.ko
sudo cp tty0tty.ko /lib/modules/$(uname -r)/kernel/drivers/misc/
sudo depmod
sudo modprobe tty0tty
Expand Down Expand Up @@ -31,3 +33,9 @@ connection: &con0096
```
mame apple2c -debug -window -flop1 net.dsk -resolution 560x384 -modem null_modem -bitb socket.localhost:2000 -nomouse
```

Quick test rebuild of Mastodon, keeping the auth file in the .dsk:
Uncomment the clisettings/mastsettings lines in ../Makefile
```
cd src/mastodon/ && make clean all; cd ../.. && make mastodon.dsk && mame apple2c -window -flop1 mastodon.dsk -resolution 560x384 -modem null_modem -bitb socket.localhost:2000 -nomouse
```
1 change: 1 addition & 0 deletions src/homecontrol-client/server_url.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const char *get_server_root_url(void) {
printf("Please enter the server's root URL,\n");
printf("Example: http://homecontrol.lan/a2domo\n");
printf("\nURL: ");
server_url[0] = '\0';
dget_text(server_url, BUFSIZE, NULL);

*strchr(server_url,'\n') = '\0';
Expand Down
8 changes: 7 additions & 1 deletion src/lib/dgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ char * __fastcall__ dget_text(char *buf, size_t size, cmd_handler_func cmd_cb) {

hy = ey - sy;

memset(buf, '\0', size - 1);
if (buf[0] != '\0') {
cur_x = wherex();
cur_y = wherey();
i = strlen(buf);
max_i = i;
rewrite_start_of_buffer(buf, i - 1, wx);
}
prev_cursor = cursor(1);

while (1) {
Expand Down
19 changes: 11 additions & 8 deletions src/mastodon/api/account.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void account_free(account *a) {
return;
free(a->id);
free(a->username);
free(a->acct);
free(a->display_name);
free(a->created_at);
free(a->note);
Expand All @@ -50,7 +51,7 @@ account *account_new_from_json(void) {
}

r = surl_get_json(gen_buf, BUF_SIZE, 0, translit_charset,
".id,.acct,.display_name,"
".id,.username,.acct,.display_name,"
".created_at,.followers_count,"
".following_count");
n_lines = strsplit_in_place(gen_buf, '\n', &lines);
Expand All @@ -59,10 +60,11 @@ account *account_new_from_json(void) {
}
a->id = strdup(lines[0]);
a->username = strdup(lines[1]);
a->display_name = strdup(lines[2]);
a->created_at = date_format(lines[3], 0);
a->followers_count = atol(lines[4]);
a->following_count = atol(lines[5]);
a->acct = strdup(lines[2]);
a->display_name = strdup(lines[3]);
a->created_at = date_format(lines[4], 0);
a->followers_count = atol(lines[5]);
a->following_count = atol(lines[6]);
free(lines);

note = malloc(2048);
Expand Down Expand Up @@ -102,17 +104,18 @@ account *api_get_profile(char *id) {
goto err_out;
}

if (surl_get_json(gen_buf, BUF_SIZE, 0, translit_charset, ".id,.display_name,.username") >= 0) {
if (surl_get_json(gen_buf, BUF_SIZE, 0, translit_charset, ".id,.display_name,.acct,.username") >= 0) {
n_lines = strsplit_in_place(gen_buf,'\n',&lines);
if (n_lines < 3) {
if (n_lines < 4) {
account_free(a);
a = NULL;
free(lines);
goto err_out;
}
a->id = strdup(lines[0]);
a->display_name = strdup(lines[1]);
a->username = strdup(lines[2]);
a->acct = strdup(lines[2]);
a->username = strdup(lines[3]);
free(lines);
}

Expand Down
1 change: 1 addition & 0 deletions src/mastodon/api/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct _account {
signed char displayed_at;
char *id;
char *username;
char *acct;
char *display_name;
/* Optionally filled fields */
char *created_at;
Expand Down
2 changes: 2 additions & 0 deletions src/mastodon/api/oauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ int do_login(void) {
dputs("Enter password: ");

echo(0);
password[0] = '\0';
dget_text(password, 50, NULL);
echo(1);
*strchr(password, '\n') = '\0';
Expand Down Expand Up @@ -250,6 +251,7 @@ int do_login(void) {

otp_again:
dputs("Enter OTP code: ");
otp[0] = '\0';
dget_text(otp, 9, NULL);
*strchr(otp, '\n') = '\0';

Expand Down
9 changes: 5 additions & 4 deletions src/mastodon/api/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ status *status_new_from_json(surl_response *resp, char *id, char full, char is_r
r = surl_get_json(gen_buf, BUF_SIZE, 0, NULL,
"(.reblog.media_attachments|map(. | select(.type==\"image\"))|length),"
".reblog.replies_count,.reblog.reblogs_count,.reblog.favourites_count,.reblog.reblogged,.reblog.favourited,"
".reblog.account.id,.reblog.account.username");
".reblog.account.id,.reblog.account.acct,.reblog.account.username");
} else {
r = surl_get_json(gen_buf, BUF_SIZE, 0, NULL,
"(.media_attachments|map(. | select(.type==\"image\"))|length),"
".replies_count,.reblogs_count,.favourites_count,.reblogged,.favourited,"
".account.id,.account.username");
".account.id,.account.acct,.account.username");
}

n_lines = strsplit_in_place(gen_buf, '\n', &lines);
if (r >= 0 && n_lines == 8) {
if (r >= 0 && n_lines == 9) {
s->n_images = atoi(lines[0]);
s->n_replies = atoi(lines[1]);
s->n_reblogs = atoi(lines[2]);
Expand All @@ -99,7 +99,8 @@ status *status_new_from_json(surl_response *resp, char *id, char full, char is_r
if (lines[5][0] == 't')
s->favorited_or_reblogged |= FAVOURITED;
s->account->id = strdup(lines[6]);
s->account->username = strdup(lines[7]);
s->account->acct = strdup(lines[7]);
s->account->username = strdup(lines[8]);
}
free(lines);

Expand Down
27 changes: 23 additions & 4 deletions src/mastodon/cli/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,34 @@ char dgt_cmd_cb(char c) {
return 0;
}

static char *handle_compose_input(void) {
static char *handle_compose_input(char *reply_to_account) {
char *text;
text = malloc(500);
if (reply_to_account && reply_to_account[0]) {
int len = strlen(reply_to_account);
int i;

for (i = 0; i < len; i++) {
if (reply_to_account[i] == '@') {
reply_to_account[i] = arobase;
break; /* no need to continue, there can only be one */
}
}
text[0] = arobase;
strncpy(text + 1, reply_to_account, 497);
text[len + 1] = ' ';
text[len + 2] = '\0';
} else {
text[0] = '\0';
}
if (dget_text(text, 500, dgt_cmd_cb) == NULL) {
free(text);
text = NULL;
}
return text;
}

void compose_toot(void) {
void compose_toot(char *reply_to_account) {
char *text;

top = wherey();
Expand All @@ -96,7 +113,7 @@ void compose_toot(void) {
set_scrollwindow(top + 1, top + COMPOSE_FIELD_HEIGHT);

gotoxy(0, 0);
text = handle_compose_input();
text = handle_compose_input(reply_to_account);

set_scrollwindow(0, scrh);

Expand Down Expand Up @@ -140,9 +157,11 @@ int main(int argc, char **argv) {
}
chline(scrw - LEFT_COL_WIDTH - 1);
dputs("Your reply:\r\n");
} else {
reply_to = NULL;
}

compose_toot();
compose_toot(reply_to != NULL ? reply_to->account->acct : "");
set_hscrollwindow(0, scrw);

params = malloc(127);
Expand Down
2 changes: 2 additions & 0 deletions src/mastodon/cli/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static int load_settings(void) {
oauth_token[0] = '\0';

dputs("Your instance: ");
instance_url[0] = '\0';
dget_text(instance_url, BUF_SIZE, NULL);
*strchr(instance_url, '\n') = '\0';
if (instance_url[0] == '\0') {
Expand All @@ -148,6 +149,7 @@ static int load_settings(void) {

dputs("If on a non-US keyboard, use @ instead of arobase.\r\n");
dputs("Your login: ");
login[0] = '\0';
dget_text(login, BUF_SIZE, NULL);
*strchr(login, '\n') = '\0';

Expand Down
1 change: 1 addition & 0 deletions src/mastodon/cli/tl.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ static int show_search(void) {
gotoxy(0, 0);
dputs("Search: ");

search_buf[0] = '\0';
dget_text(search_buf, 49, NULL);

if (search_buf[0] != '\0') {
Expand Down
3 changes: 3 additions & 0 deletions src/stp/stp.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ char *get_start_url(void) {
printf("\n\nURL: ");

start_url = malloc(BUFSIZE + 1);
start_url[0] = '\0';
dget_text(start_url, BUFSIZE, NULL);
if (strchr(start_url,'\n'))
*strchr(start_url,'\n') = '\0';
Expand All @@ -98,6 +99,7 @@ char *get_start_url(void) {
}

login = malloc(BUFSIZE + 1);
login[0] = '\0';
dget_text(login, BUFSIZE, NULL);
if (strchr(login,'\n'))
*strchr(login,'\n') = '\0';
Expand All @@ -106,6 +108,7 @@ char *get_start_url(void) {
password = last_password;
} else {
password = malloc(BUFSIZE + 1);
password[0] = '\0';
printf("Password: ");
echo(0);
dget_text(password, BUFSIZE, NULL);
Expand Down
1 change: 1 addition & 0 deletions src/stp/stp_send_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static unsigned char scrw = 255, scrh = 255;

static char *stp_send_dialog() {
char *filename = malloc(BUFSIZE);
filename[0] = '\0';

if (scrw == 255)
screensize(&scrw, &scrh);
Expand Down
1 change: 1 addition & 0 deletions src/telnet/telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ int main(int argc, char **argv) {
char t;

buf = malloc(BUFSIZE);
buf[0] = '\0';
dputs("Enter host:port: ");
dget_text(buf, BUFSIZE, NULL);
dputs("Translate LN <=> CRLN (N/y)? ");
Expand Down

0 comments on commit 742ff85

Please sign in to comment.