我想使用Print
函数调用将一些文本打印到屏幕上。有没有办法(或任何其他功能)来设置文本的颜色?
问问题
435 次
2 回答
0
这将设置您的打印颜色:
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_YELLOW); //SET TEXT COLOR
只需EFI_COLORNAME -> 红色、黄色、绿色、蓝色等。但是,它非常有限。
为了再次设置颜色,我们使用代码:
`uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_BACKGROUND_MAGENTA);` //SET BACK COLOR
只需EFI_BACKGROUND_COLORNAME -> 磁铁,黑色,蓝色,棕色等等。但是,它非常有限。我认为您可以定义自定义颜色,例如EFI_BACKGROUND_MYSPECIALCOLOR
还有基于gnu的完整代码:
/*
* UEFI:SIMPLE - UEFI development made easy
* Copyright © 2014-2018 Pete Batard <pete@akeo.ie> - Public Domain
* See COPYING for the full licensing terms.
*/
#include <efi.h>
#include <efilib.h>
#include <stdio.h>
// Application entrypoint (must be set to 'efi_main' for gnu-efi crt0 compatibility)
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
UINTN Event;
#if defined(_GNU_EFI)
InitializeLib(ImageHandle, SystemTable);
#endif
/*
* In addition to the standard %-based flags, Print() supports the following:
* %N Set output attribute to normal
* %H Set output attribute to highlight
* %E Set output attribute to error
* %B Set output attribute to blue color
* %V Set output attribute to green color
* %r Human readable version of a status code
*/
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_BACKGROUND_MAGENTA); //SET BACK COLOR
Print(L"\n***DO NOT DISPLAY THIS***%N\n\n");
uefi_call_wrapper(SystemTable->ConOut->ClearScreen, 1, SystemTable->ConOut); //CLEAR SCREEN
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_YELLOW); //SET TEXT COLOR
Print(L"\n*** UEFI:HELLO MY FRIEND, bla bla and some other very necessary messages... ***%N\n\n");
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, EFI_RED); //SET TEXT COLOR
Print(L"PRESS ANY KEY TO EXIT.%N\n");
SystemTable->ConIn->Reset(SystemTable->ConIn, FALSE);
SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &Event);
#if defined(_DEBUG)
// If running in debug mode, use the EFI shut down call to close QEMU
SystemTable->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
#endif
return EFI_SUCCESS;
}
如果您问如何更改打印自己的单元格背景。嗯,IDK。
于 2020-11-25T22:15:54.250 回答
-1
要更改控制台文本的颜色,您可以使用 -
system("color enter_code_here_choose_value_from_instructions_below"); /*First include <stdlib.h>*/
例如-
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]){
system("color 1");//1 is the value of blue
printf("Colored text");
return 0;
}
注意:我无法提供颜色值,因为 Stack Overflow 将它们作为代码忽略。在 Windows 中获取它们的说明-
打开cmd并输入color show。使用提供的代码替换上面的“enter_code_here_choose_value_from_instructions_below”。
此外,更改控制台颜色不会有什么好处。
彩色文本仅在图形库中很重要。
我建议你在学习了 C 的基础知识之后再学习 SIGIL(图形库)。
于 2019-09-22T16:59:30.693 回答