Tiny Core Base > Raspberry Pi

Disable blinking cursor in terminal from C program.

(1/2) > >>

AlexM:
Hello!
I need to disable the blinking cursor in the text console from my C program to work directly with the framebuffer.
I'm using this code:

--- Code: ---#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/kd.h>
#include <unistd.h>
#include <stdio.h>

//...
char *tty_n;
int console_fd;

if ((tty_n = ttyname(0)) == NULL){
    fprintf(stderr,"ttyname() error.\n");
    exit(1);
}

console_fd = open(tty_n, O_RDWR);

if (!console_fd) {
    fprintf(stderr,"Could not open console.\n");
    exit(1);
}

if (ioctl( console_fd, KDSETMODE, KD_GRAPHICS))
{
fprintf(stderr,"Could not set console to KD_GRAPHICS mode.\n");
exit(1);
}

close(console_fd);
//...
--- End code ---
It works on Tiny Core with TC.tcz installed, but does not work on minimal piCore. The error is returned by ioctl( console_fd, KDSETMODE, KD_GRAPHICS).
Installing TC.tcz increases the loading time, which I would like to avoid and I do not need graphical desctop. But I don’t have enough knowledge of which component is missing for the code to work and whether it can be installed separately from TC.tcz.
Perhaps there is some other way to solve this problem?
OS version piCore 13, board - Raspberry Pi Zero W.

Rich:
Hi AlexM
Welcome to the forum.

Try this:

--- Code: ---system("echo -e \e[?25l");
--- End code ---

Rich:
Hi AlexM

Sorry, I forgot to include  stdlib.h.

Hide.c:

--- Code: ---#include <stdio.h>
#include <stdlib.h>

int main ()
{

   system("echo -e \e[?25l");

   return(0);
}
--- End code ---

Show.c:

--- Code: ---#include <stdio.h>
#include <stdlib.h>

int main ()
{

   system("echo -e \e[?25h");

   return(0);
}
--- End code ---

Compile:

--- Code: ---gcc Hide.c -o Hide
gcc Show.c -o Show
--- End code ---

./Hide  will hide the cursor. This works in both a virtual terminal
as provided by  TC.tcz  as well as the console which you want
to be running in.

./Show  will of course make the cursor visible again.

curaga:
If you have a framebuffer available, it could be as simple as a permission error. Check the errno code after that ioctl.

AlexM:

--- Quote from: Rich on September 18, 2023, 08:32:01 AM ---Try this:

--- Code: ---system("echo -e \e[?25l");
--- End code ---

--- End quote ---
Thanks, it work!


--- Quote from: curaga on September 18, 2023, 12:41:29 PM ---If you have a framebuffer available, it could be as simple as a permission error. Check the errno code after that ioctl.

--- End quote ---
ioctl return error "Bad file descriptor"

Navigation

[0] Message Index

[#] Next page

Go to full version