Difference between pages "Is dark mode" and "File to buffer"

From Kolmafia
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
 
<onlyinclude>{{{{{format|Function2}}}
 
<onlyinclude>{{{{{format|Function2}}}
|name=is_dark_mode
+
|name=file_to_buffer
|function1.return_type=boolean
+
|function1.return_type=buffer
|function1.description=Checks if the current KoLmafia theme is dark mode.
+
|function1.description=Loads the entire contents of a text file into a buffer.
|description=Checks if the current KoLmafia theme is one of the "dark mode" themes. This function was added in r20566.
+
|function1.param1=filepath
 +
|function1.param1.type=string
 +
|function1.param1.description=Path to the text file
 +
|description=<p>This does not ignore empty lines, or lines starting with <code>#</code>.</p>
 +
 
 +
<p>This function was added in [https://kolmafia.us/threads/19439-you-can-create-a-bottle-of-sea-wine-by-using-a-bunch-of-sea-grapes-add-some-a.24054/ r19439].</p>
 
|code1={{CodeSample
 
|code1={{CodeSample
 
   |title=Code Samples
 
   |title=Code Samples
   |description=Use a different text color based on the user's theme.
+
   |description=Load the contents of a text file.
 
   |code=
 
   |code=
<syntaxhighlight lang="java">
+
<syntaxhighlight lang="d">
string WARN_COLOR = is_dark_mode() ? "#FFFF00" : "#A0522D";
+
buffer data = file_to_buffer("mydata.txt");
print("This is a warning.", WARN_COLOR);
+
print(`Number of characters in mydata.txt: {data.length()}`);
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  |moreinfo=
 
}}
 
}}
 +
|see_also={{SeeAlso|buffer_to_file|file_to_array|file_to_map|map_to_file}}
 +
|cli_equiv=
 +
|more_info=
 
|special=
 
|special=
 
|{{{1|}}}
 
|{{{1|}}}
 
}}</onlyinclude>
 
}}</onlyinclude>
 
[[Category:Miscellaneous Functions]]
 
[[Category:Miscellaneous Functions]]

Latest revision as of 05:33, 21 December 2020

Function Syntax

buffer file_to_bufferstring filepath )

Loads the entire contents of a text file into a buffer.
  • filepath: Path to the text file

This does not ignore empty lines, or lines starting with #.

This function was added in r19439.

Code Samples

Load the contents of a text file.

buffer data = file_to_buffer("mydata.txt");
print(`Number of characters in mydata.txt: {data.length()}`);

See Also

buffer_to_file() | file_to_array() | file_to_map() | map_to_file()