gpt4 book ai didi

c - 设置使用 Print (gnu-efi) 打印的文本颜色

转载 作者:行者123 更新时间:2023-11-30 20:41:59 25 4
gpt4 key购买 nike

我想使用 Print 函数调用将一些文本打印到屏幕上。有没有什么方法(或任何其他函数)来设置文本的颜色?

最佳答案

这将设置您的打印颜色:

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;
}

如果你问如何改变print自己的单元格背景。好吧,我不知道。

关于c - 设置使用 Print (gnu-efi) 打印的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58050463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com