Files
ConsoleMenu/console_functions.c
felicianoa237 72674393e3 INIT
2024-12-23 11:46:18 -06:00

97 lines
2.5 KiB
C

//
// Created by tony on 11/27/2024.
//
#include <windows.h>
#include <stdio.h>
#include <stdbool.h>
#include "entities.h"
// Function to clear the console
static void clearConsole()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = {0, 0};
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the console screen buffer info
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the console with spaces
FillConsoleOutputCharacter(hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten);
// Reset the cursor to the top left
SetConsoleCursorPosition(hConsole, coordScreen);
}
static void enableANSI()
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = 0;
// Get the current console mode
if (GetConsoleMode(hOut, &dwMode))
{
// Enable the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag
SetConsoleMode(hOut, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
}
// Function to set cursor position
static void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
static bool updateConsole(struct Entity *pEntity)
{
HANDLE lhConsole = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD pCharsWritten;
Entity *toScreen = pEntity;
/* if (!WriteConsoleOutputCharacter(lhConsole,
toScreen.avatar,
1,
toScreen.position,
&pCharsWritten)) {
printf("Error: Unable to write to console. Error code: %ld\n", GetLastError());
return 0;
}*/
return 1;
}
static void getBufferInfo(HANDLE *hHandle, CONSOLE_SCREEN_BUFFER_INFO *pCSBI)
{
GetConsoleScreenBufferInfo(hHandle, pCSBI);
}
void printList(HANDLE *pHConsole, DWORD **pCharsWritten, Entity *e)
{
//HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD *CharsWritten;
while (e != NULL)
{
if (!WriteConsoleOutputCharacter(pHConsole,
&e->avatar,
1,
e->position,
&pCharsWritten)) {
// printf("Error: Unable to write to console. Error code: %ld\n", GetLastError());
}
// printf("Avatar :%s",&e->avatar);
e = (Entity *) e->next;
}
}