{"id":175,"date":"2019-09-30T22:28:33","date_gmt":"2019-09-30T19:28:33","guid":{"rendered":"http:\/\/www.potansif.com\/?p=175"},"modified":"2019-10-01T16:24:47","modified_gmt":"2019-10-01T13:24:47","slug":"linux-cursor-position-ve-text-attributte-api-muadili","status":"publish","type":"post","link":"http:\/\/www.potansif.com\/?p=175","title":{"rendered":"Linux : Cursor Position ve Text Attributte API Muadili"},"content":{"rendered":"<p><b>Soru<\/b><\/p>\n<p>Bilindi\u011fi \u00fczere Tokyo s\u00fcr\u00fcm\u00fcyle beraber&nbsp;Linux i\u00e7in konsol uygulamalar\u0131 geli\u015ftirebiliyoruz. Windows konsol ortam\u0131nda imle\u00e7 pozisyonu&nbsp;ve text renklendirmeleri i\u00e7in<!--more-->&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/console\/setconsolecursorposition\">SetConsoleCursorPosition<\/a> ve&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/console\/setconsoletextattribute\">SetConsoleTextAttribute<\/a> gibi&nbsp;baz\u0131 API&#8217;leri&nbsp;kullan\u0131yoruz. Bu API&#8217;ler text ekranda ( konsolda \/ Ms-DOS ekran\u0131nda&nbsp;) imlecin konumunu \/ metnin zemin ve metin rengini ayarlamaya yar\u0131yor.<\/p>\n<p>Bu API&#8217;lerin Linux e\u015fde\u011feri hangisidir, nereden bulabilirim?<\/p>\n<p><b>Cevap<\/b><\/p>\n<pre><code>program Renkli;\r\n\r\n{$APPTYPE CONSOLE}\r\n\r\nuses\r\n&nbsp; &nbsp; System.SysUtils&nbsp; &nbsp;\/\/&nbsp; Format\r\n&nbsp; {$IFDEF MSWINDOWS}&nbsp; \/\/&nbsp; Windows ise\r\n&nbsp; , WinApi.Windows&nbsp; &nbsp; \/\/&nbsp; SetConsoleTextAttribute , SetConsoleCursorPosition\r\n&nbsp; {$ENDIF}\r\n&nbsp; ;\r\n\r\nconst\r\n&nbsp; clBlack&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&nbsp; &nbsp;0;\r\n&nbsp; clBlue&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&nbsp; &nbsp;1;\r\n&nbsp; clGreen&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&nbsp; &nbsp;2;\r\n&nbsp; clCyan&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&nbsp; &nbsp;3;\r\n&nbsp; clRed&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&nbsp; &nbsp;4;\r\n&nbsp; clMagenta&nbsp; &nbsp; &nbsp; &nbsp;=&nbsp; &nbsp;5;\r\n&nbsp; clBrown&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&nbsp; &nbsp;6;\r\n&nbsp; clSilver&nbsp; &nbsp; &nbsp; &nbsp; =&nbsp; &nbsp;7;\r\n\r\n&nbsp; {$IFDEF MSWINDOWS}\r\n&nbsp; clDarkGray&nbsp; &nbsp; &nbsp; =&nbsp; &nbsp;8;\r\n&nbsp; clLightBlue&nbsp; &nbsp; &nbsp;=&nbsp; &nbsp;9;\r\n&nbsp; clLightGreen&nbsp; &nbsp; =&nbsp; 10;\r\n&nbsp; clLightCyan&nbsp; &nbsp; &nbsp;=&nbsp; 11;\r\n&nbsp; clLightRed&nbsp; &nbsp; &nbsp; =&nbsp; 12;\r\n&nbsp; clLightMagenta&nbsp; =&nbsp; 13;\r\n&nbsp; clYellow&nbsp; &nbsp; &nbsp; &nbsp; =&nbsp; 14;\r\n&nbsp; clWhite&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=&nbsp; 15;\r\n&nbsp; {$ENDIF}\r\n\r\nprocedure Color(Zemin, Metin: Integer);\r\nbegin\r\n&nbsp; {$IFDEF MSWINDOWS}\r\n&nbsp; &nbsp; SetConsoleTextAttribute ( GetStdHandle(STD_OUTPUT_HANDLE)\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , (Zemin * 16) or Metin\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );\r\n&nbsp; {$ENDIF}\r\n&nbsp; {$IFNDEF MSWINDOWS}\r\n&nbsp; &nbsp; Write( Format(#27'[%d'#27'[%d', [Zemin + 40, Metin + 30] ) );\r\n&nbsp; {$ENDIF}\r\nend;\r\n\r\nprocedure CLS;\r\n{$IFDEF MSWINDOWS}\r\nvar\r\n&nbsp; CRT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: THandle;\r\n&nbsp; Bufinf&nbsp; &nbsp; &nbsp; : TConsoleScreenBufferInfo;\r\n&nbsp; ConsoleSize : DWORD;\r\n&nbsp; NumWritten&nbsp; : DWORD;\r\n&nbsp; Koordinat&nbsp; &nbsp;: TCoord;\r\n{$ENDIF}\r\nbegin\r\n&nbsp; {$IFDEF MSWINDOWS}\r\n&nbsp; &nbsp; CRT := GetStdHandle(STD_OUTPUT_HANDLE);\r\n&nbsp; &nbsp; Win32Check(CRT &lt;&gt; INVALID_HANDLE_VALUE);\r\n&nbsp; &nbsp; Win32Check(GetConsoleScreenBufferInfo(CRT, Bufinf));\r\n&nbsp; &nbsp; ConsoleSize := Bufinf.dwSize.X * Bufinf.dwSize.Y;\r\n&nbsp; &nbsp; Koordinat.X := 0;\r\n&nbsp; &nbsp; Koordinat.Y := 0;\r\n&nbsp; &nbsp; Win32Check(FillConsoleOutputCharacter(CRT, ' ', ConsoleSize, Koordinat, NumWritten));\r\n&nbsp; &nbsp; Win32Check(FillConsoleOutputAttribute(CRT, Bufinf.wAttributes, ConsoleSize, Koordinat, NumWritten));\r\n&nbsp; &nbsp; Win32Check(SetConsoleCursorPosition(CRT, Koordinat));\r\n&nbsp; {$ENDIF}\r\n&nbsp; {$IFNDEF MSWINDOWS}\r\n&nbsp; &nbsp; write(#27'[2J');\r\n&nbsp; {$ENDIF}\r\nend;\r\n\r\nprocedure GotoXY(X,Y: Byte);\r\n{$IFDEF MSWINDOWS}\r\nvar\r\n&nbsp; Z: _COORD;\r\n{$ENDIF}\r\nbegin\r\n&nbsp; {$IFDEF MSWINDOWS}\r\n&nbsp; &nbsp; Z.X := X;\r\n&nbsp; &nbsp; Z.Y := Y;\r\n&nbsp; &nbsp; SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), Z );\r\n&nbsp; {$ENDIF}\r\n&nbsp; {$IFNDEF MSWINDOWS}\r\n&nbsp; &nbsp; Write( Format(#27'[%d;%dH', [X.ToString, Y.ToString]) );\r\n&nbsp; {$ENDIF}\r\nend;\r\n\r\nfunction Print(aMetin: String): string; overload;\r\nbegin\r\n&nbsp;Result := aMetin;\r\n&nbsp; Write(Result);\r\nend;\r\n\r\nfunction Print(X, Y: Byte; aMetin: String): string; overload;\r\nbegin\r\n&nbsp;Result := aMetin;\r\n&nbsp; GotoXY(X, Y);\r\n&nbsp; Write(Result);\r\nend;\r\n\r\nfunction Print(aMetin: String; const Args: array of const): string; overload;\r\nbegin\r\n&nbsp;Result := format(aMetin, Args);\r\n&nbsp; Write(Result);\r\nend;\r\n\r\nfunction Print(X, Y: Byte; aMetin: String; const Args: array of const): string; overload;\r\nbegin\r\n&nbsp; GotoXY(X, Y);\r\n&nbsp;Result := Print(aMetin, Args);\r\nend;\r\n\r\nprocedure Pencere(aBaslik: AnsiString; X, Y, B, E: Byte; Zemin, Metin: Integer);\r\nvar\r\n&nbsp; I: Integer;\r\nbegin\r\n&nbsp; Color(Zemin, Metin);\r\n&nbsp; Print(X,Y, '\u250c%s\u2510', [StringOfChar('\u2500', E - 2)]);\r\n&nbsp; for I := 1 to B - 2&nbsp;\r\n&nbsp; do&nbsp; Print(X, Y + I, '\u2502%s\u2502', [StringOfChar(' ', E - 2)]);\r\n&nbsp; Print(X, Y + I, '\u2514%s\u2518', [StringOfChar('\u2500', E - 2)]);\r\n&nbsp; Print(X + 2, Y, '[%s]', [aBaslik]);\r\nend;\r\n\r\nvar\r\n&nbsp; I, J, X: Integer;\r\nbegin\r\n&nbsp; CLS;\r\n&nbsp; Pencere('Bi Pencere', 2, 2, 15, 35, clSilver, clRed);\r\n&nbsp; Color(clSilver, clGreen);\r\n&nbsp; Print(4, 4, 'T\u00fcrk\u00e7e Harf Testleri&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ');\r\n&nbsp; Print(4, 5, '\u00e7\u00f6\u011f\u00fc\u015fi\u0131 \/ \u00c7\u00d6\u011e\u00dc\u015e\u0130I \/ 0123456789');\r\n&nbsp; Color(clBlack, clSilver);\r\n&nbsp; Print(0, 0, '');\r\n&nbsp; Readln;\r\nend.<\/code><\/pre>\n<p>\u015e\u00f6yle de bir ekran \u00e7\u0131kt\u0131s\u0131 \u00fcretiyor&#8230;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-594\" src=\"http:\/\/rubicube.com.tr\/wp-content\/uploads\/2018\/09\/rJ1MEP1.png\" alt=\"\" width=\"979\" height=\"512\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bilindi\u011fi \u00fczere Tokyo s\u00fcr\u00fcm\u00fcyle beraber&nbsp;Linux i\u00e7in konsol uygulamalar\u0131 geli\u015ftirebiliyoruz. Windows konsol ortam\u0131nda imle\u00e7 pozisyonu&nbsp;ve text renklendirmeleri i\u00e7in<\/p>\n","protected":false},"author":1,"featured_media":262,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[43,4,40,11,42,41,44],"class_list":["post-175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-ansi-escape-sequence","tag-delphi","tag-linux","tag-programlama","tag-setconsolecursorposition","tag-setconsoletextattribute","tag-soru-cevap"],"_links":{"self":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175"}],"version-history":[{"count":1,"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":182,"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions\/182"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/media\/262"}],"wp:attachment":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}