~alcinnz/rhapsode

c15af78521d97e025f5f09fb4d3a659928c2d2f5 — Adrian Cochrane 4 years ago a8275ac
Add arrow key navigation inside pages.
1 files changed, 26 insertions(+), 11 deletions(-)

M src/main.c
M src/main.c => src/main.c +26 -11
@@ 117,30 117,44 @@ int speak_initialize() {
    samplerate = espeak_ng_GetSampleRate();
    return 0;
}
void speak(char *ssml) {
void speak(char *ssml, char *mark) {
    int flags = espeakCHARS_AUTO | espeakPHONEMES | espeakENDPAUSE | espeakCHARS_UTF8 | espeakSSML;
    espeak_Synth(ssml, strlen(ssml)+1, 0, POS_CHARACTER, 0, flags, NULL, NULL);
    if (mark != NULL) espeak_Synth_Mark(ssml, strlen(ssml)+1, mark, 0, flags, NULL, NULL);
    espeak_Synth(ssml, strlen(ssml)+1, 0, POS_CHARACTER, 0, flags, NULL, NULL); // FIXME only do so if mark doesn't play.
}
int read_keyboard = 0;
int speak_finalize() {
int speak_finalize(char *ssml) {
    while (read_keyboard) {
        char c = getc(stdin);
        if (c == '\033') {
            char mark[200];
            espeak_Cancel();
            c = getc(stdin);
            if (c == 0 || c == -1 || c == '\033' || c == 'q') goto close; // skip [
            switch (getc(stdin)) {
            case 'A':
                printf("🠕");
                // 🠕
                section_no--;
                sprintf(mark, "-rhaps-section%i", section_no);
                speak(ssml, section_no > 0 ? mark : NULL);
                break;
            case 'B':
                printf("🠗");
                // 🠗
                section_no++;
                sprintf(mark, "-rhaps-section%i", section_no);
                speak(ssml, section_no > 0 ? mark : NULL);
                break;
            case 'C':
                printf("➔");
                // ➔
                paragraph_no++;
                sprintf(mark, "-rhaps-paragraph%i", paragraph_no);
                speak(ssml, paragraph_no > 0 ? mark : NULL);
                break;
            case 'D':
                printf("🠔");
                // 🠔
                paragraph_no--;
                sprintf(mark, "-rhaps-paragraph%i", paragraph_no);
                speak(ssml, paragraph_no > 0 ? mark : NULL);
                break;
            }
        }


@@ 234,21 248,22 @@ int main(int argc, char **argv) {
    struct page *referer = c_initialReferer();

    if (use_espeak) speak_err = speak_initialize();
    char *ssml;
    for (int i = optind; i < argc; i++) {
        if (use_espeak && speak_err == 0) speak(argv[i]);
        if (use_espeak && speak_err == 0) speak(argv[i], NULL);
        else printf("%s\n", argv[i]);

        struct page *page = c_fetchURL(session, mimes, referer, argv[i]);
        char *ssml = c_renderDoc(session, page, use_espeak);
        ssml = c_renderDoc(session, page, use_espeak);
        char **links = c_extractLinks(page);

        if (fd_ssml != NULL) fprintf(fd_ssml, "%s\n", ssml);
        if (fd_links != NULL) write_links(fd_links, links);
        if (use_espeak & speak_err == 0) speak(ssml);
        if (use_espeak & speak_err == 0) speak(ssml, "main");

        c_freePage(page);
    }
    if (use_espeak & speak_err == 0) speak_err = speak_finalize();
    if (use_espeak & speak_err == 0) speak_err = speak_finalize(ssml);

    c_freePage(referer);
    c_freeSession(session);