about summary refs log tree commit diff stats
path: root/src/ui/notifier.c
Commit message (Expand)AuthorAgeFilesLines
* auto-formatSteffen Jaeckel2022-02-011-2/+2
* Format code correctlyMichael Vetter2021-10-051-1/+1
* notifier: Use glib functionMichael Vetter2021-09-091-3/+2
* Simplify notify()Michael Vetter2020-12-091-2/+2
* Apply coding styleMichael Vetter2020-07-071-21/+20
* Revert "Apply coding style"Michael Vetter2020-07-071-23/+24
* Apply coding styleMichael Vetter2020-07-071-24/+23
* Fix gcc warnings for cygwinDmitry Podgorny2020-06-241-3/+4
* Free GError objectsDmitry Podgorny2020-04-141-2/+3
* Add vim modelineMichael Vetter2019-11-131-0/+1
* Update copyright to include 2019Michael Vetter2019-01-221-1/+1
* Update copyrightJames Booth2018-01-211-1/+1
* Update CopyrightJames Booth2017-01-281-1/+1
* Correct minor spelling errorsJack Henschel2016-09-271-1/+1
* Tidy headersJames Booth2016-07-241-3/+5
* Moved muc.cJames Booth2016-07-241-1/+1
* Update GPL link in headersJames Booth2016-07-241-1/+1
* Fix OSX compileJames Booth2016-04-261-0/+1
* Removed #AX_PREFIX_CONFIG_HJames Booth2016-03-311-7/+7
* Fixed PLATFORM_CYGWIN referencesJames Booth2016-03-101-2/+2
* Merge branch 'master' into plugins-cJames Booth2016-02-141-1/+1
|\
| * Updated copyrightJames Booth2016-02-141-1/+1
* | Added C plugin code from plugins branchJames Booth2016-02-141-19/+16
|/
* Tidy notify_room_message()James Booth2016-02-041-3/+8
* Tidy notify_message()James Booth2016-02-041-3/+8
* Removed unused arg: prefs_do_chat_notify()James Booth2016-02-041-1/+1
* Only show reminder notifications when notifications are enabledJames Booth2015-11-251-2/+3
* Tidy regular chat and room notificationsJames Booth2015-11-241-22/+13
* Removed ui_unreadJames Booth2015-11-021-1/+1
* Applied coding style to src/ui/James Booth2015-10-251-9/+8
* Moved ui/windows -> window_listJames Booth2015-06-151-1/+1
* Moved logic to notify_messageJames Booth2015-05-101-9/+17
* Use null check convention in notifier.cJames Booth2015-05-041-4/+4
* Use single quotes for terminal notifier notifications to avoid variable expan...James Booth2015-02-141-6/+4
* Updated copyrightJames Booth2015-02-101-1/+1
* Moved remimder notification code out of main loopJames Booth2015-01-151-31/+47
* Removed function pointersJames Booth2014-12-221-28/+15
* Tidied muc moduleJames Booth2014-09-281-1/+1
* Small spelling fixes in code and commentsDariusz Dwornikowski2014-08-271-1/+1
* Added license exemption for OpenSSL to source headersJames Booth2014-08-241-0/+12
* Escape open bracket at start of OSX notification messagesJames Booth2014-08-041-1/+17
* Escape backtick in mac terminal notificationsJames Booth2014-08-041-3/+5
* Fixed tabsJames Booth2014-06-291-5/+5
* Reinitialise libnotify per notificationJames Booth2014-06-291-11/+13
* Escape strings passed to terminal-notifierJames Booth2014-05-241-3/+6
* Added settings to show message text in notificationsJames Booth2014-05-241-12/+17
* Removed strcpy callsJames Booth2014-04-021-3/+3
* Updated copyrightJames Booth2014-03-091-1/+1
* Added configure checks to enable desktop notifications on OSXJames Booth2014-03-041-0/+2
* Log message when cannot send desktop noficationJames Booth2014-03-041-1/+5
ernel.soso/tty.c?h=main&id=ded2b24ce28f4a9df75ce40117f0f06f09574369'>^
67de9b02 ^
46bb1d31 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153


                  
                                                                                            























                                                                 
                           




                                       
                                                                 


                                                   
                       





                              
                             




                                                

                                                               









                                                                                           
                                                       




                                     
                          


                                        
                                                             







                              
                                    

                                        
                                 


                               
                                                     






                                                                  

                                     







                                                                                                 

                                           











                                                                                                     
                                                 



                               
                                                 













                                                                            
                                              
                         
                




                             
                                                           


                                
#include "tty.h"
#include "alloc.h"

Tty* createTty(uint16 lineCount, uint16 columnCount, TtyFlushScreenFunction flushFunction) {
    Tty* tty = kmalloc(sizeof(Tty));
    memset((uint8*)tty, 0, sizeof(Tty));

    tty->lineCount = lineCount;
    tty->columnCount = columnCount;
    tty->buffer = kmalloc(tty->lineCount * tty->columnCount * 2);
    tty->currentColumn = 0;
    tty->currentLine = 0;
    tty->color = 0x0A;

    memset(tty->lineBuffer, 0, TTY_LINEBUFFER_SIZE);
    tty->lineBufferIndex = 0;
    tty->keyBuffer = FifoBuffer_create(64);
    tty->flushScreen = flushFunction;

    tty->term.c_cc[VMIN] = 1;
    tty->term.c_lflag |= ECHO;
    tty->term.c_lflag |= ICANON;

    Tty_Clear(tty);

    return tty;
}

void destroyTty(Tty* tty) {
    FifoBuffer_destroy(tty->keyBuffer);
    kfree(tty->buffer);
    kfree(tty);
}

void Tty_Print(Tty* tty, int row, int column, const char* text) {
    unsigned char * video = tty->buffer;

    video += (row * tty->columnCount + column) * 2;
    while(*text != 0) {
        *video++ = *text++;
        *video++ = tty->color;
    }
}

//One line
void Tty_ScrollUp(Tty* tty) {
    unsigned char * videoLine = tty->buffer;
    unsigned char * videoLineNext = tty->buffer;
    int line = 0;
    int column = 0;

    for (line = 0; line < tty->lineCount - 1; ++line) {
        for (column = 0; column < tty->columnCount; ++column) {
            videoLine = tty->buffer + (line * tty->columnCount + column) * 2;
            videoLineNext = tty->buffer + ((line + 1) * tty->columnCount + column) * 2;

            videoLine[0] = videoLineNext[0];
            videoLine[1] = videoLineNext[1];
        }
    }

    //Last line should be empty.
    unsigned char * lastLine = tty->buffer + ((tty->lineCount - 1) * tty->columnCount) * 2;
    for (int i = 0; i < tty->columnCount * 2; i += 2) {
        lastLine[i] = 0;
        lastLine[i + 1] = tty->color;
    }
}

void Tty_Clear(Tty* tty) {
    unsigned char * video = tty->buffer;
    int i = 0;

    for (i = 0; i < tty->lineCount * tty->columnCount; ++i) {
        *video++ = 0;
        *video++ = tty->color;
    }

    tty->currentLine = 0;
    tty->currentColumn = 0;
}

void Tty_PutChar(Tty* tty, char c) {
    unsigned char * video = tty->buffer;

    if ('\n' == c || '\r' == c) {
        ++tty->currentLine;
        tty->currentColumn = 0;

        if (tty->currentLine >= tty->lineCount - 0) {
            --tty->currentLine;
            Tty_ScrollUp(tty);
        }

        Tty_MoveCursor(tty, tty->currentLine, tty->currentColumn);
        return;
    }
    else if ('\b' == c) {
        if (tty->currentColumn > 0) {
            --tty->currentColumn;
            c = '\0';
            video = tty->buffer + (tty->currentLine * tty->columnCount + tty->currentColumn) * 2;
            video[0] = c;
            video[1] = tty->color;
            Tty_MoveCursor(tty, tty->currentLine, tty->currentColumn);
            return;
        }
        else if (tty->currentColumn == 0) {
            if (tty->currentLine > 0) {
                --tty->currentLine;
                tty->currentColumn = tty->columnCount - 1;
                c = '\0';
                video = tty->buffer + (tty->currentLine * tty->columnCount + tty->currentColumn) * 2;
                video[0] = c;
                video[1] = tty->color;
                Tty_MoveCursor(tty, tty->currentLine, tty->currentColumn);
                return;
            }
        }
    }

    if (tty->currentColumn >= tty->columnCount) {
        ++tty->currentLine;
        tty->currentColumn = 0;
    }

    if (tty->currentLine >= tty->lineCount - 0) {
        --tty->currentLine;
        Tty_ScrollUp(tty);
    }

    video += (tty->currentLine * tty->columnCount + tty->currentColumn) * 2;

    video[0] = c;
    video[1] = tty->color;

    ++tty->currentColumn;

    Tty_MoveCursor(tty, tty->currentLine, tty->currentColumn);
}

void Tty_PutText(Tty* tty, const char* text) {
    const char* c = text;
    while (*c) {
        Tty_PutChar(tty, *c);
        ++c;
    }
}

void Tty_MoveCursor(Tty* tty, uint16 line, uint16 column) {
    tty->currentLine = line;
    tty->currentColumn = column;
}