ConsoleBase - NKS0007
Use TWC.Write()
This analyzer provides the following strings:
Error List
Caller uses Console.Write
instead of TWC.Write()
Suggestion Box
Use TWC.Write()
instead of Console.Write
Description
TextWriterColor.Write()
contains workarounds for VT sequences needed for Linux hosts to properly report the correct position post-write. Its overloads also allow you to specify the color and the line writing.
Extended Description
This code analyzer detects the usage of Write
from the standard Console
class found in the System
namespace. The Write
function from that class used to be so good in Nitrocid's very early days until we started to support Linux systems.
Since then, we were suffering from the VT sequence problems and the correct positioning of the Linux console cursor, causing Console.CursorLeft
and CursorTop
to report incorrect values. We've made a wrapper class that works around this problem using the GetFilteredPositions
function from ConsoleExtensions
, and it worked well on most situations, especially after the usage of the master VT sequence regular expression matching.
TextWriterColor.Write()
deals with this scenario before trying to use the plain writer to write to the console so that the cursor positioning is correct after the write. It also uses your current console driver for further flexibility.
Analysis Comparison
To get a brief insight about how this analyzer works, compare the two code blocks shown to you below:
Before the fix
After the fix
Suppression
You can suppress this suggestion by including it in the appropriate place, whichever is convenient.
For more information about how to suppress any warning issued by the Nitrocid analyzer, visit the below page:
Recommendation
We recommend that every caller which use this property use the recommended abovementioned method.
Last updated