我正在编写.NET Core控制台应用程序.我想将控制台输入限制为每个输入的特定数量的最大字符.我有一些代码通过构建一个字符串Console.ReadKey()
而不是Console.ReadLine()
Everything在Windows上完美地测试它来实现这一点.然后,当我部署到运行Raspbian的Raspberry Pi 3时,我很快遇到了各种各样的问题.我记得Linux处理行结尾的方式与Windows不同,似乎退格处理方式也不同.我改变了处理它们的方式,取消了ConsoleKey而不是字符,换行问题消失了,但退格只是有时会注册.此外,有时字符会输出到我输入框外的控制台,即使我将ReadKey设置为不自行输出到控制台.我错过了Linux处理控制台输入的方法吗?
//I replaced my calls to Console.ReadLine() with this. The limit is the
//max number of characters that can be entered in the console.
public static string ReadChars(int limit)
{
string str = string.Empty; //all the input so far
int left = Console.CursorLeft; //store cursor position for re-outputting
int top = Console.CursorTop;
while (true) //keep checking for key events
{
if (Console.KeyAvailable)
{
//true to intercept input and not output to console
//normally. …
Run Code Online (Sandbox Code Playgroud) 我有一个元素(注释列表和表单),在我的应用程序的许多地方使用.它工作得很好,花花公子,除了它需要刷新整个页面.这可能会有问题,特别是当它重置您的评论所属的游戏时,会导致所有进展失败.我对AJAX的经验非常有限,那么用添加的注释重新加载元素的最有效,最简单的方法是什么?
这是我的元素:
<?php
/*
set variables:
$data : data of the parent
$type : the type of the parent
$name : (optional)unique name to avoid naming conflicts
*/
if(!isset($name)) {
$name = 0;
}
foreach($data['Comment'] as $comment){
echo '<div class="comment">'.$comment['content'].
' - '.$this->Html->link($comment['User']['username'],array('controller'=>'users','action'=>'view',$comment['User']['id']))
.'</div>';
}
echo $this->Form->create(null, array('url' => '/comments/add','id'=>'qCommentForm'));
echo $this->Html->link('Leave comment','javascript:toggleDisplay("comment'.$name.'")');
echo '<br><div id="comment'.$name.'" style="display:none;">';
echo $this->Form->input('Comment.parent_id', array('type'=>'hidden','value'=>$data[$type]['id']));
echo $this->Form->input('Comment.parent_type', array('type'=>'hidden','value'=>$type));
echo $this->Form->textarea('Comment.content',array('div'=>'false','class'=>'small','label'=>false));
echo $this->Form->submit(__('Leave comment'),array('div'=>'false','class'=>'small'));
echo '</div>';
echo $this->Form->end();
?>
Run Code Online (Sandbox Code Playgroud)
好的,所以我更了解ajax,感谢您的帖子,但我仍然不明白如何做到这一点的"蛋糕方式".