@@ -14,6 +14,9 @@ namespace Chubrik.XConsole;
14
14
#if NET
15
15
using System . Runtime . Versioning ;
16
16
#endif
17
+ #if NET9_0_OR_GREATER
18
+ using System . Threading ;
19
+ #endif
17
20
#if NET7_0_OR_GREATER
18
21
using System . Diagnostics . CodeAnalysis ;
19
22
#endif
@@ -52,7 +55,11 @@ public static class XConsole
52
55
53
56
private static readonly string _newLine = Environment . NewLine ;
54
57
private static readonly bool _positioningEnabled ;
58
+ #if NET9_0_OR_GREATER
59
+ private static readonly Lock _syncLock = new ( ) ;
60
+ #else
55
61
private static readonly object _syncLock = new ( ) ;
62
+ #endif
56
63
57
64
private static bool _coloringEnabled = Environment . GetEnvironmentVariable ( "NO_COLOR" ) == null ;
58
65
private static bool _cursorVisible ;
@@ -565,7 +572,10 @@ internal static ConsolePosition WriteToPosition(
565
572
{
566
573
#if NET
567
574
if ( ! OperatingSystem . IsWindows ( ) && keyInfo . KeyChar == '\x1a ' )
575
+ {
576
+ Console . WriteLine ( ) ;
568
577
return null ;
578
+ }
569
579
#endif
570
580
if ( isMaskedMode )
571
581
Console . Write ( maskChar ) ;
@@ -1190,6 +1200,30 @@ public static (ConsolePosition Begin, ConsolePosition End) Write(
1190
1200
return WriteBase ( [ ConsoleItem . Parse ( string . Format ( format , arg ?? [ ] ) ) ] , isWriteLine : false ) ;
1191
1201
}
1192
1202
1203
+ #if NET9_0_OR_GREATER
1204
+ /// <summary>
1205
+ /// <inheritdoc cref="Console.Write(string, ReadOnlySpan{object?})"/>
1206
+ /// Text can be colored using a simple <see href="https://github.com/chubrik/XConsole#coloring">microsyntax</see>.
1207
+ /// </summary>
1208
+ /// <param name="format">
1209
+ /// A composite format string.
1210
+ /// Text can be colored using a simple <see href="https://github.com/chubrik/XConsole#coloring">microsyntax</see>.
1211
+ /// </param>
1212
+ /// <returns><inheritdoc cref="Write(string?)"/></returns>
1213
+ /// <inheritdoc cref="Console.Write(string, ReadOnlySpan{object?})"/>
1214
+ public static ( ConsolePosition Begin , ConsolePosition End ) Write (
1215
+ [ StringSyntax ( StringSyntaxAttribute . CompositeFormat ) ] string format , params ReadOnlySpan < object ? > arg )
1216
+ {
1217
+ if ( format . Length == 0 )
1218
+ {
1219
+ var position = CursorPosition ;
1220
+ return ( position , position ) ;
1221
+ }
1222
+
1223
+ return WriteBase ( [ ConsoleItem . Parse ( string . Format ( format , arg ) ) ] , isWriteLine : false ) ;
1224
+ }
1225
+ #endif
1226
+
1193
1227
/// <inheritdoc cref="Console.Write(uint)"/>
1194
1228
/// <returns><inheritdoc cref="Write(string?)"/></returns>
1195
1229
public static ( ConsolePosition Begin , ConsolePosition End ) Write ( uint value )
@@ -1377,6 +1411,27 @@ public static (ConsolePosition Begin, ConsolePosition End) WriteLine(
1377
1411
return WriteBase ( [ ConsoleItem . Parse ( string . Format ( format , arg ?? [ ] ) ) ] , isWriteLine : true ) ;
1378
1412
}
1379
1413
1414
+ #if NET9_0_OR_GREATER
1415
+ /// <summary>
1416
+ /// <inheritdoc cref="Console.WriteLine(string, ReadOnlySpan{object?})"/>
1417
+ /// Text can be colored using a simple <see href="https://github.com/chubrik/XConsole#coloring">microsyntax</see>.
1418
+ /// </summary>
1419
+ /// <param name="format">
1420
+ /// A composite format string.
1421
+ /// Text can be colored using a simple <see href="https://github.com/chubrik/XConsole#coloring">microsyntax</see>.
1422
+ /// </param>
1423
+ /// <returns><inheritdoc cref="WriteLine(string?)"/></returns>
1424
+ /// <inheritdoc cref="Console.WriteLine(string, ReadOnlySpan{object?})"/>
1425
+ public static ( ConsolePosition Begin , ConsolePosition End ) WriteLine (
1426
+ [ StringSyntax ( StringSyntaxAttribute . CompositeFormat ) ] string format , params ReadOnlySpan < object ? > arg )
1427
+ {
1428
+ if ( format . Length == 0 )
1429
+ return WriteLine ( ) ;
1430
+
1431
+ return WriteBase ( [ ConsoleItem . Parse ( string . Format ( format , arg ) ) ] , isWriteLine : true ) ;
1432
+ }
1433
+ #endif
1434
+
1380
1435
/// <inheritdoc cref="Console.WriteLine(uint)"/>
1381
1436
/// <returns><inheritdoc cref="WriteLine(string?)"/></returns>
1382
1437
public static ( ConsolePosition Begin , ConsolePosition End ) WriteLine ( uint value )
@@ -1790,15 +1845,18 @@ public static int WindowTop
1790
1845
}
1791
1846
1792
1847
/// <inheritdoc cref="Console.WindowWidth"/>
1793
- #if NET
1794
- [ UnsupportedOSPlatform ( "android" ) ]
1795
- [ UnsupportedOSPlatform ( "browser" ) ]
1796
- [ UnsupportedOSPlatform ( "ios" ) ]
1797
- [ UnsupportedOSPlatform ( "tvos" ) ]
1798
- #endif
1799
1848
public static int WindowWidth
1800
1849
{
1850
+ #if NET
1851
+ [ UnsupportedOSPlatform ( "android" ) ]
1852
+ [ UnsupportedOSPlatform ( "browser" ) ]
1853
+ [ UnsupportedOSPlatform ( "ios" ) ]
1854
+ [ UnsupportedOSPlatform ( "tvos" ) ]
1855
+ #endif
1801
1856
get => Console . WindowWidth ;
1857
+ #if NET
1858
+ [ SupportedOSPlatform ( "windows" ) ]
1859
+ #endif
1802
1860
set
1803
1861
{
1804
1862
lock ( _syncLock )
@@ -1807,15 +1865,18 @@ public static int WindowWidth
1807
1865
}
1808
1866
1809
1867
/// <inheritdoc cref="Console.WindowHeight"/>
1810
- #if NET
1811
- [ UnsupportedOSPlatform ( "android" ) ]
1812
- [ UnsupportedOSPlatform ( "browser" ) ]
1813
- [ UnsupportedOSPlatform ( "ios" ) ]
1814
- [ UnsupportedOSPlatform ( "tvos" ) ]
1815
- #endif
1816
1868
public static int WindowHeight
1817
1869
{
1870
+ #if NET
1871
+ [ UnsupportedOSPlatform ( "android" ) ]
1872
+ [ UnsupportedOSPlatform ( "browser" ) ]
1873
+ [ UnsupportedOSPlatform ( "ios" ) ]
1874
+ [ UnsupportedOSPlatform ( "tvos" ) ]
1875
+ #endif
1818
1876
get => Console . WindowHeight ;
1877
+ #if NET
1878
+ [ SupportedOSPlatform ( "windows" ) ]
1879
+ #endif
1819
1880
set
1820
1881
{
1821
1882
lock ( _syncLock )
@@ -1834,10 +1895,7 @@ public static void SetWindowPosition(int left, int top)
1834
1895
1835
1896
/// <inheritdoc cref="Console.SetWindowSize(int, int)"/>
1836
1897
#if NET
1837
- [ UnsupportedOSPlatform ( "android" ) ]
1838
- [ UnsupportedOSPlatform ( "browser" ) ]
1839
- [ UnsupportedOSPlatform ( "ios" ) ]
1840
- [ UnsupportedOSPlatform ( "tvos" ) ]
1898
+ [ SupportedOSPlatform ( "windows" ) ]
1841
1899
#endif
1842
1900
public static void SetWindowSize ( int width , int height )
1843
1901
{
0 commit comments