Git Product home page Git Product logo

Comments (9)

ikozyris avatar ikozyris commented on June 1, 2024 1

FINALLY IT WORKS!!!

#include <ncurses.h>

int main() {
    initscr();
    keypad(stdscr, TRUE);
    int ch,y,x;
    wmove(stdscr,0,0);
    getyx(stdscr,x,y);
    while(1) {
        ch = getch();        
        switch(ch)  {
            case KEY_DOWN:
                x=x+1;
                wmove(stdscr,x, y);
                break;
            case KEY_UP:
                x=x-1;
                wmove(stdscr,x, y);
                break;
            case KEY_LEFT:
                y=y-1;
                wmove(stdscr,x, y);
                break;
            case KEY_RIGHT:
                y=y+1;
                wmove(stdscr,x, y);
                break;

        }
    }
    return 0;
}


Now, I have to add it to the program, which is the most difficult part…

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

UPDATE: A solution would be to get the x, y of physical cursor (https://linux.die.net/man/3/getyx) and… something like this:
if (ch == KEY_RIGHT x++) move(x,y);
something like this…
Also, this is interesting…

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

UPDATE: I got working getting the cursor position, but the noted part to move the cursor doesn't work:

#include <ncurses.h>

int main() {
    int y,x,ch;
    WINDOW *win = initscr();
/////below does not work
        ch = getch(); 
        switch(ch)
        {
            case KEY_DOWN:
                y-=1;
                break;
            case KEY_UP:
                y+=1;
                break;
            case KEY_LEFT:
                x+=1;
                break;
            case KEY_RIGHT:
                x-=1;
                break;
        } 
/////above does not work
    mvaddstr(0, 0, "Hello world!");
    refresh();
    getyx(win, y, x);
    printf("%d %d",x,y);
    x-=3;
    y+=4;
    mvprintw(y, x, "X: %d, Y: %d", x, y);
    refresh();
    getch();
    endwin();  
}

(not sure if the x, y movements are correct) Also, press enter to see the output. Problem is: when any key is pressed, it stops.

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

Except from the ncurses library, there are also the escape codes:

up - "\033[A"
down - "\033[B"
left - "\033[D"
right - "\033[C"

for X terminals like gnome-terminal and Xterm

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

UPDATE: I got working getting the cursor position, but the noted part to move the cursor doesn't work:

#include <ncurses.h>

int main() {
    int y,x,ch;
    WINDOW *win = initscr();
/////below does not work
        ch = getch(); 
        switch(ch)
        {
            case KEY_DOWN:
                y-=1;
                break;
            case KEY_UP:
                y+=1;
                break;
            case KEY_LEFT:
                x+=1;
                break;
            case KEY_RIGHT:
                x-=1;
                break;
        } 
/////above does not work
    mvaddstr(0, 0, "Hello world!");
    refresh();
    getyx(win, y, x);
    printf("%d %d",x,y);
    x-=3;
    y+=4;
    mvprintw(y, x, "X: %d, Y: %d", x, y);
    refresh();
    getch();
    endwin();  
}

(not sure if the x, y movements are correct) Also, press enter to see the output. Problem is: when any key is pressed, it stops.

I should remove WINDOW *win and I should add this: keypad(stdscr, TRUE); 😆

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

Except from the ncurses library, there are also the escape codes:

up - "\033[A"
down - "\033[B"
left - "\033[D"
right - "\033[C"

for X terminals like gnome-terminal and Xterm

For this approach, termios.h could be better.

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

It needs a rebase... There has been some slight behind the scenes progress for an ncurses rebase, but no text editing functionality yet working (saving, reading buffer, etc).

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

Follow the progress on the ncurses branch. Currently the only issue is suppressing the ctrl x key output while using default key bindings for every other key.

from yocto.

ikozyris avatar ikozyris commented on June 1, 2024

On the ncurses branch, you can find the program (main.c) This issue is resolved, but not merged into the main branch.

from yocto.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.